Orders Execution
0
Views
0
Downloads
0
Favorites
STORM
//+------------------------------------------------------------------+
//| STORM.mq4 |
//| Copyright ©, Íèêîíîâ Äåíèñ Âèêòîðîâè÷ |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright ©Íèêîíîâ Äåíèñ Âèêòîðîâè÷, dzedan@list.ru"
#define MAGIC 240406
//---- input parameters
extern int ExtDepth=2;
extern int ExtDeviation=5;
extern int ExtBackstep=3;
extern double AStopLoss = 150; // Ñòîï âíà÷àëå ñåññèè
extern double ATakeProfit = 25; // Òåéê âíà÷àëå ñåññèè
extern double Lots=2;
extern int LotsWayChoice = 7; // Ñïîñîá âûáîðà ðàáî÷åãî ëîòà:
// 0-ôèêñèðîâàííûé,
// 1-ïðîöåíò îò äåïîçèòà
extern double DefaultVolume=1; //Îáúåì îðäåðà ïî óìîë÷àíèþ. Ìàêñèìàëüíûé îáúåì êîòîðûé äàñò ìàðòèíãåéë = DefaultVolume*2^MartingaleDeep;
extern int MartingaleDeep=7; //Ìàñêèìàëüíûé ïîêàçàòåëü ñòåïåíè ìàðòèíãåéëà.
extern int LotsPercent=4; // Ïðîöåíò îò äåïîçèòà
extern string Symb="*";
extern int TimeFrame=0;
int i,STP,UD,UDP,TF,DG,MN,PNT;
string SMB;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int LongStats[16];
int ShortStats[16];
double MaxVolume;
double MinVolume;
double StartVolume;
double LastAccountBalance;
double KellyCorrection=1;
double TotalWinCounter=1;
double TotalLooseCounter=1;
int MartingaleType=0;
int bbars;
int Counter1=0;
int Counter2=0;
int Result=0;
int init()
{
LastAccountBalance=AccountBalance();
for (int i=0;i<17;i++)
{
LongStats[i]=2;
ShortStats[i]=1;
}
MinVolume=DefaultVolume;
MaxVolume=DefaultVolume*MathPow(2,MartingaleDeep-1);
bbars=Bars;
if(Symb=="*") SMB=Symbol(); else SMB=Symb;
if(TimeFrame==0) TF=Period(); else TF=TimeFrame;
DG=MarketInfo(SMB,MODE_DIGITS);
MN=MAGIC+TF;
PNT=MarketInfo(SMB,MODE_POINT);
STP=MarketInfo(SMB,MODE_STOPLEVEL)*PNT;
UDP=0;
return(0);
return(0);
}
int deinit()
{
//----
//----
return(0);
}
//double GetSizeLot()
// {
// double Lot = Lots;
// int cycle;
// int prof = 0;
// int orders = HistoryTotal(); // history orders total
// int losses = 0; // number of losses orders without a break
// int vinn = 0;
// int i = orders;
// if (LotsWayChoice==0) Lot=Lots;
// ôèêñèðîâàííûé ïðîöåíò îò äåïîçèòà
// if (LotsWayChoice==1) {
// Lot=MathCeil(AccountFreeMargin()/10000*LotsPercent)/10;
// }
// return(Lot);
// }
//+------------------------------------------------------------------+
//| ôóêêöèÿ èíèöèàëèçàöèè ýêñïåðòà |||||||||||||||||||||||||||||||||||
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| ôóêêöèÿ äåèíèöèàëèçàöèè ýêñïåðòà |||||||||||||||||||||||||||||||||
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| îñíîâíàÿ ôóíêöèÿ |||||||||||||||||||||||||||||||||||||||||||||||||
//+------------------------------------------------------------------+
int start()
{
double zc,zp,zcn,zpn,CO,PR;
bool f;
//----
int buff,LastResult;
double P,Q,A,B;
if ((bbars!=Bars)&&(Time[0]-TimeCurrent()==0))
{
//OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
// OrderClose(OrderTicket(),OrderLots(),Bid,20);
//OrderClose(OrderTicket(),OrderLots(),Ask,20);
Counter2++;
bbars=Bars;
if (AccountBalance()>LastAccountBalance)
TotalWinCounter++;
if (AccountBalance()<LastAccountBalance)
TotalLooseCounter++;
P=TotalWinCounter/(TotalWinCounter+TotalLooseCounter);
Q=1-P;
A=(ATakeProfit +AStopLoss)/ATakeProfit;
B=(ATakeProfit +AStopLoss)/AStopLoss;
KellyCorrection=MathAbs((P/B)-(Q/A));
if (MartingaleType ==0)
{
if (Counter1==1)
DefaultVolume=MinVolume;
if (AccountBalance()>LastAccountBalance)
{
DefaultVolume=DefaultVolume*2;
}
}
if (MartingaleType ==1)
{
if (Counter1==1)
DefaultVolume=MaxVolume;
if (AccountBalance()>LastAccountBalance)
{
DefaultVolume=DefaultVolume/2;
}
}
if (MartingaleType ==2)
{
if (Counter1==1)
DefaultVolume=MinVolume;
if (AccountBalance()<LastAccountBalance)
{
DefaultVolume=DefaultVolume*2;
}
}
if (MartingaleType ==3)
{
if (Counter1==1)
DefaultVolume=MaxVolume;
if (AccountBalance()<LastAccountBalance)
{
DefaultVolume=DefaultVolume/2;
}
}
if (MartingaleType ==4)
{
if (Counter1==1)
DefaultVolume=MinVolume;
if (AccountBalance()>LastAccountBalance)
{
DefaultVolume=DefaultVolume*2;
}
if (AccountBalance()<LastAccountBalance)
{
DefaultVolume=DefaultVolume/2;
}
}
if (MartingaleType ==5)
{
if (Counter1==1)
DefaultVolume=MinVolume;
if (AccountBalance()>LastAccountBalance)
{
DefaultVolume=DefaultVolume/2;
}
if (AccountBalance()<LastAccountBalance)
{
DefaultVolume=DefaultVolume*2;
}
}
if (MartingaleType ==6)
{
if (Counter1==1)
DefaultVolume=MinVolume;
DefaultVolume=DefaultVolume*2;
}
if (MartingaleType ==7)
{
if (Counter1==1)
DefaultVolume=MaxVolume;
DefaultVolume=DefaultVolume/2;
}
LastResult=Result;
if ((Close[1]-Open[1])>0)
{
buff=LastResult+8;
LongStats[buff]++;
}
if ((Close[1]-Open[1])<0)
{
buff=LastResult+8;
ShortStats[buff]++;
}
LastAccountBalance=AccountBalance();
if ((MartingaleType==7)&&(Counter1==MartingaleDeep))
MartingaleType=0;
if (Counter1==MartingaleDeep)
{
MartingaleType++;
Counter1=0;
}
Counter1++;
}
for(f=true,i=2;i<Bars;i++)
{
zp=iCustom(SMB,TF,"ZigZag",ExtDepth,ExtDeviation,ExtBackstep,0,i);
if(zp>0) { if(f) { f=false; zc=zp; } else break; }
}
if(zp<zc)
{
UD=OP_BUYLIMIT;
PR=NormalizeDouble((zc-zp)/10,DG);
CO=NormalizeDouble((zp+zc)/2.0+PR,DG);
} else
if(zp>zc)
{
UD=OP_SELLLIMIT;
PR=NormalizeDouble((zp-zc)/10,DG);
CO=NormalizeDouble((zp+zc)/2.0-PR,DG);
} else return(0);
if(PR<10*PNT) return(0);
for(i=0;i<OrdersTotal();i++)
{
OrderSelect(i,SELECT_BY_POS);
if(OrderSymbol()!=SMB || OrderMagicNumber()!=MN) continue;
if(OrderType()==OP_BUY) continue;
if(OrderType()==OP_SELL) continue;
if(OrderType()==OP_SELLLIMIT)
{
if(UD==OP_BUYLIMIT) OrderDelete(OrderTicket()); else
if(OrderOpenPrice()!=CO) OrderModify(OrderTicket(),CO,0,CO+PR,0,CLR_NONE);
return(0);
}
if(OrderType()==OP_BUYLIMIT)
{
if(UD==OP_SELLLIMIT) OrderDelete(OrderTicket()); else
if(OrderOpenPrice()!=CO) OrderModify(OrderTicket(),CO,0,CO-PR,0,CLR_NONE);
return(0);
}
}
for(f=true,i=0;i<Bars;i++)// îïðåä. 2-é çèãçàã
{
zpn=iCustom(SMB,TF,"ZigZag",ExtDepth,ExtDeviation,ExtBackstep,0,0);
if(zpn>0) { if(f) { f=false; zcn=zpn; } else break; }
}
if(zpn<=0) {zcn=zc; zpn=zp;}
if(UD==OP_SELLLIMIT && UDP!=OP_SELLLIMIT && zcn<CO)
{
if(CO-MarketInfo(SMB,MODE_ASK)<STP) return(0);
OrderSend(SMB,OP_SELLLIMIT,DefaultVolume,CO,3,GetStopLossSell(),GetTakeProfitSell(),NULL,MN,0,Red);
UDP=UD;
} else
if(UD==OP_BUYLIMIT && UDP!=OP_BUYLIMIT && zcn>CO)
{
if(MarketInfo(SMB,MODE_BID)-CO<STP) return(0);
OrderSend(SMB,OP_BUYLIMIT,DefaultVolume,CO,3,GetStopLossBuy(),GetTakeProfitBuy(),NULL,MN,0,Blue);
UDP=UD;
}
Print(" zp=",zp," zc=",zc," zpn=",zpn," zcn=",zcn," CO=",CO);
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double GetStopLossBuy()
{
return (Bid - AStopLoss*Point);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double GetStopLossSell()
{
return(Ask + AStopLoss*Point);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double GetTakeProfitBuy()
{
return(Ask + ATakeProfit*Point);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double GetTakeProfitSell()
{
return(Bid - ATakeProfit*Point);
}
//----
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---