Learn to code.
Not tested, not compiled, just typed.
for(int count=1; count < 9; ++count){ RefreshRates(); if(total==count && Bid-PriceS>HT*count){ ticket=OrderSend(Symbol(),OP_SELL,Lots*(count+1),Bid,5,0,TPS,"Original",0,0,Red); } } // for
Not tested, not compiled, just typed.
Depending on what is the 'PriceS'. Looks like this is the price of the lowest sell order.
If you just want to simplify this code, then there is a dependency here:
if(total > 0 && total < 9 && Bid - PriceS > HT * total) { double orderLots = Lot * (total + 1); // Should be normalized // ticket=OrderSend(...) }
But still, it's not good.
I think something like this would be a little better:
const int MAX_ORDERS_NUMBER = 8; void addingGridOrders(double priceOfNextOrder, double lotOfNextOrder, int ordersNumber) { if(ordersNumber < 1 || ordersNumber >= MAX_ORDERS_NUMBER) return; if(Bid < priceOfNextOrder) return; ticket=OrderSend(Symbol(),OP_SELL,lotOfNextOrder,Bid,5,0,TPS,"Original",0,0,Red); }
where
priceOfNextOrder = NormalizeDouble(PriceS + HT * ordersNumber, Digits()); lotOfNextOrder = Lot * (ordersNumber + 1);
This is not code ready to use. I'm just trying to convey the idea to you
Depending on what is the 'PriceS'. Looks like this is the price of the lowest sell order.
If you just want to simplify this code, then there is a dependency here:
But still, it's not good.
I think something like this would be a little better:
where
This is not code ready to use. I'm just trying to convey the idea to you
The point is to reduce the condition to this:
if(Bid < priceOfNextOrder) return;
That is, if the price at which the next grid order should be added is reached, then we add it.
I just flipped the condition to avoid nesting. It could look like this:
if(Bid >= priceOfNextOrder) ticket=OrderSend(Symbol(),OP_SELL,lotOfNextOrder,Bid,5,0,TPS,"Original",0,0,Red);
And the price of the next order is most conveniently calculated where you get the 'PriceS'
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi Everyone
What is the simplest way to set variables in order to avoid the repetitiveness, please? (total means OrdersTotal)