Sorry dudes, I'm very new to coding, but trying hard - a little help needed.
I use hedging, not stop losses. I always have many trades open.
I want to "balance trades" so that "sell lots = buy lots" when a trigger is reached (either when a % equity profit is reached, or a % equity loss is reached).
Example: I have many open trades which are 2.04 lots of Sell, 0.16 lots of Buy. When TargetBestEquity is reached, I need to balance open and sell trades with an OP_BUY of 1.88 lots....thus making the both sides equal to 2.04 lots.
But I can't seem to use it as a lots variable in the OrderSend() balancing trade.
So, (as an example) my EA fails when I try to use (total_buylots-total_selllots) as the lots quantity in a Ordersend().
I can print to the chart the correct lots count, but I must be doing something silly to not be able to use it in the OrderSend().
All ideas and help gratefully appreciated.
Phil
I use hedging, not stop losses. I always have many trades open.
I want to "balance trades" so that "sell lots = buy lots" when a trigger is reached (either when a % equity profit is reached, or a % equity loss is reached).
Example: I have many open trades which are 2.04 lots of Sell, 0.16 lots of Buy. When TargetBestEquity is reached, I need to balance open and sell trades with an OP_BUY of 1.88 lots....thus making the both sides equal to 2.04 lots.
But I can't seem to use it as a lots variable in the OrderSend() balancing trade.
Inserted Code
double total_selllots =0; //define variable total_sellots, starting at =0 double total_buylots =0; //define variable total_buylots, starting at =0 //Calculate total_buylots for (int i = OrdersTotal()-1; i >=0; i--) //scanning all trades { if (! OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { Sleep(10); continue; } if(OrderSymbol() == Symbol() && OrderMagicNumber()==Magic) //check the currency and magic number are correct { if (OrderType() == OP_BUY) //with OP_BUY trades { total_buylots = total_buylots + OrderLots(); //add them up and keep a tally of them } //Calculate total_selllots if (OrderType() == OP_SELL) //with the OP_SELL trades { total_selllots = total_selllots + OrderLots(); //add them up and keep a tally of them too }
So, (as an example) my EA fails when I try to use (total_buylots-total_selllots) as the lots quantity in a Ordersend().
I can print to the chart the correct lots count, but I must be doing something silly to not be able to use it in the OrderSend().
Inserted Code
string strTotalLots; strTotalLots="Total BUY LOTS = " + DoubleToStr(total_buylots,2) + "\n"; strTotalLots=strTotalLots+"Total SELL LOTS = " + DoubleToStr(total_selllots,2) + "\n"; strTotalLots=strTotalLots+"Total ALL LOTS = " + DoubleToStr(total_selllots+total_buylots,2) + "\n";
All ideas and help gratefully appreciated.
Phil