Attachment:
pyramiding_v1.0.mol [40.08 KiB]
Downloaded 493 times
The mol file is attached.
Also I am attaching the modifications in the EA below:
Code:
// This module returns pt=1 if open positions are long, pt=-1 if short and pt=0 if no positions are open.
int last_trade=OrdersTotal();
if(last_trade>0)
{
if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==true)
{
if (OrderMagicNumber()==35) // This is the magic number for long positions.
int pt = 1;
else
pt = -1;
}
}
else
pt=0;
// Trading code starts here
if (TradeOrAlert) {
// Check conditions
if ( CONDITIONS FOR CLOSING LONG )
{ CLOSELONG(Symbol()) ;}
if (pt!=-1&& CONDITIONS FOR OPENING THE FIRST SHORT POSITION)
{ SELL(Symbol(),S_Symbol_LS_0,...}
if ( CONDITIONS FOR CLOSING SHORT )
{ CLOSESHORT(Symbol()) ;}
if (pt!=1&&CONDITIONS FOR OPENING THE FIRST LONG POSITION)
{ BUY(Symbol(),B_Symbol_LS_3,...}
//This module reopens long positions 0.2, 0.4 and 0.8 if profit of open trades is negative (every 40 pips)
if (( pt==1&&AccountProfit()<-506&&OrdersTotal()==3 ) )
{ BUY(Symbol(),B_Symbol_LS_0,B_Symbol_TP_0,B_Symbol_SL_0,B_Symbol_TS_0,"i...") ;}
if (( pt==1&&AccountProfit()<-180&&OrdersTotal()==2 ) )
{ BUY(Symbol(),B_Symbol_LS_1,B_Symbol_TP_1,B_Symbol_SL_1,B_Symbol_TS_1,"if...") ;}
if (( pt==1&&AccountProfit()<-50&&OrdersTotal()==1 ) )
{ BUY(Symbol(),B_Symbol_LS_2,B_Symbol_TP_2,B_Symbol_SL_2,B_Symbol_TS_2,"if ...") ;}
// This module reopens short positions 0.2, 0.4 and 0.8 if profit of open trades is negative (every 40 pips)
if (( pt==-1&&AccountProfit()<-506&&OrdersTotal()==3 ) )
{ SELL(Symbol(),S_Symbol_LS_1,S_Symbol_TP_1,S_Symbol_SL_1,S_Symbol_TS_1,"if ...") ;}
if (( pt==-1&&AccountProfit()<-180&&OrdersTotal()==2 ) )
{ SELL(Symbol(),S_Symbol_LS_2,S_Symbol_TP_2,S_Symbol_SL_2,S_Symbol_TS_2,"if ...") ;}
if (( pt==-1&&AccountProfit()<-50&&OrdersTotal()==1 ) )
{ SELL(Symbol(),S_Symbol_LS_3,S_Symbol_TP_3,S_Symbol_SL_3,S_Symbol_TS_3,"if ...") ;}
I am sure this was not a very professional way of doing it, but it works!