-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path009 Martingale Descending.mq4
49 lines (41 loc) · 3.1 KB
/
009 Martingale Descending.mq4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
extern double Lots=0.01,MaxLots=0.5,LotExponent=1,Multiplier=1.5;
extern uchar TakeProfit=50,StopLoss=180,Counts=5;
int ihl,iM=1,TradeLost,TradeCount=0;
int start(){
//if(ihl!=Time[0]){ ihl=Time[0];
bool lC; // (Local}) Order function checking
char lI=LorC(0,false); // (Local) Count trade
if(lI!=0) return 0; // Cancel off trade and reset
double lS=StopLoss*Point,lL=Lots,lD=0,lT=TakeProfit*Point; // (Local) Step size, Lot size, Direction [0=Buy,1=Sell]
for(int i=OrdersHistoryTotal()-1;i>=0;i--){
lC=OrderSelect(i,0,1);
if(OrderSymbol()==Symbol()&&OrderMagicNumber()==0){
if(OrderType()==0) lD=1;
else lD=0;
if(TradeCount>Counts){
TradeCount=0;
}
if(OrderProfit()<0){
lL=NormalizeDouble(Lots*MathPow(LotExponent,TradeCount),2);
TradeCount++;
lS*=(Counts-TradeCount)/Counts;
lT*=(Counts-TradeCount)/Counts;
}
break;
}
}
if(lD==1) lC=OrderSend(Symbol(),1,lL,Bid,5,Bid+lS,Bid-lT); else lC=OrderSend(Symbol(),0,lL,Ask,5,Ask-lS,Ask+lT);
//}
return 0;
}
double LorC(char a=0, bool b=true){ //Last Price or Count
char cFC,i;
bool c;
for(i=OrdersTotal()-1;i>=0;i--){
c=OrderSelect(i,0);
if(OrderSymbol()==Symbol()&&OrderMagicNumber()==a)
if(!b)cFC++;
else return OrderOpenPrice();
}
return cFC;
}