I wish MLQ4 would allow me to..... (newbie)

 

I want to set MLQ4 to automatically close any trade that reaches (-$40.00) in the Profit column on the Trade tab.

More info:

I use two EAs that trade multiple pairs and are attached one each to EURUSD and GBPUSD.

These EAs work well except one of them tends to let the Profit column fall below (-$90.00) before closing (using the Stop Loss setting)

I want to put in a setting that will close any trade that falls below (-$40.00) thereby overriding the Stop Loss of the EAs.

Is it possible for a newbie or anyone for that matter to do that in MLQ4?

Thank you

 
for(int i=OrdersTotal()-1;i>=0;i--){
 OrderSelect(i,SELECT_BY_POS);
 if(OrderProfit()<=(-40)) OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,CLR_NONE);
}
//z
 
zzuegg:
//z


Thank you!

I used the language editor and made this:

//+------------------------------------------------------------------+

//| zzuegg.mq4 |

//| Copyright © 2011, MetaQuotes Software Corp. |

//| http://www.metaquotes.net |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2011, MetaQuotes Software Corp."

#property link "http://www.metaquotes.net"


//+------------------------------------------------------------------+

//| expert initialization function |

//+------------------------------------------------------------------+

int init()

{

//----

for(int i=OrdersTotal()-1;i>=0;i--){


OrderSelect(i,SELECT_BY_POS);


if(OrderProfit()<=(-40)) OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,CLR_NONE);


}

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert start function |

//+------------------------------------------------------------------+

int start()

{

//----

//----

return(0);

}

//+------------------------------------------------------------------+

Thank you for your help.

pgodbold

 
It seems to me that your code should be in the start() function, not in the init() function. The init() function only runs once, when you drop the EA on a chart or start the tester. The start() function runs on every tick. You do realize that by overriding the stop loss you will probably reduce your profits more than your losses?