Your broken English question is unclear. Please explain your question in more detail.
Also your value from "HedgeNow*Pips()" is a price range in points, not a quote price. So it is not comparable to the Bid (or Ask) quote prices. They are of different units and scale.
EDIT: Also, your Pips() function is useless, as it returns "10 * Point" for both an odd and even number of digits.
Your broken English question is unclear. Please explain your question in more detail.
Also your value from "HedgeNow*Pips()" is a price range in points, not a quote price. So it is not comparable to the Bid (or Ask) quote prices. They are of different units and scale.
EDIT: Also, your Pips() function is useless, as it returns "10 * Point" for both an odd and even number of digits.
In that case, then first fix what I have already identified and then come back with the new code for further analyses, but fix the following as well ...
As it stands now, as soon as you place one trade, then no further processing is done because your Trade() function is only called when no positions exist.
So separate the code for the first trade from the code for the hedge trade so that it will still run after the first trade is placed.
Fix this too, before presenting your updated code.
In that case, then first fix what I have already identified and then come back with the new code for further analyses, but fix the following as well ...
As it stands now, as soon as you place one trade, then no further processing is done because your Trade() function is only called when no positions exist.
So separate the code for the first trade from the code for the hedge trade so that it will still run after the first trade is placed.
Fix this too, before presenting your updated code.
I've used this function a lot of times and I've not encountered any problems and it works fine on every pair (FX, XAU/USD & indices).
double Pips() { double PipPoint=0; int Digit=(int)SymbolInfoInteger(Symbol(),SYMBOL_DIGITS); if(Digit==1||Digit==2||Digit==3){PipPoint=Point()*10;} if(Digit==4||Digit==5){PipPoint=Point()*10;} return(PipPoint); }
If you know the problem please correct me where I'm wrong.
In that case, then first fix what I have already identified and then come back with the new code for further analyses, but fix the following as well ...
As it stands now, as soon as you place one trade, then no further processing is done because your Trade() function is only called when no positions exist.
So separate the code for the first trade from the code for the hedge trade so that it will still run after the first trade is placed.
Fix this too, before presenting your updated code.
Same problem as before
void Trade() { double Ask=SymbolInfoDouble(Symbol(),SYMBOL_ASK); double Bid=SymbolInfoDouble(Symbol(),SYMBOL_BID); MqlRates Candle[]; ArraySetAsSeries(Candle,true); int rates=CopyRates(Symbol(),Period(),0,Bars(Symbol(),Period()),Candle); double BuyHedge=Bid-HedgeNow*_Point; double SellHedge=Bid+HedgeNow*_Point; if(Candle[1].close<Candle[1].open) { Buy=trade.Buy(0.01,Symbol(),Ask,0,0,"TestHedge"); if(Buy>0&&BuyHedge) { Sell=trade.Sell(0.01,Symbol(),Bid,0,0,"TestHedge"); } } if(Candle[1].close>Candle[1].open) { Sell=trade.Sell(0.01,Symbol(),Bid,0,0,"TestHedge"); if(Sell>0&&SellHedge) { Buy=trade.Buy(0.01,Symbol(),Ask,0,0,"TestHedge"); } } }
double Pips() { double PipPoints = _Point; switch( _Digits ) { case 1: case 3: case 5: PipPoints *= 10; }; return PipPoints; };
Please note, that you should only use Pips for those symbols that support it (e.g. Forex). Don't use it for other symbols (e.g. Stocks or Futures).
Fernando Carreiro #:
Obviously it is the same problem. You did not separate the code, and you also did not show any changes in OnTick().
double Pips2() { double point=_Point; switch(_Digits){case 1:case 3:case 5:point*=10;} return(point); } void Trade() { double Ask=SymbolInfoDouble(Symbol(),SYMBOL_ASK); double Bid=SymbolInfoDouble(Symbol(),SYMBOL_BID); MqlRates Candle[]; ArraySetAsSeries(Candle,true); int rates=CopyRates(Symbol(),Period(),0,Bars(Symbol(),Period()),Candle); double BuyHedge=Bid-HedgeNow*Pips2(); double SellHedge=Bid+HedgeNow*Pips2(); if(Candle[1].close<Candle[1].open) { Buy=trade.Buy(0.01,Symbol(),Ask,0,0,"TestHedge"); } if(Candle[1].close>Candle[1].open) { Sell=trade.Sell(0.01,Symbol(),Bid,0,0,"TestHedge"); } } void Hedge() { double Ask=SymbolInfoDouble(Symbol(),SYMBOL_ASK); double Bid=SymbolInfoDouble(Symbol(),SYMBOL_BID); MqlRates Candle[]; ArraySetAsSeries(Candle,true); int rates=CopyRates(Symbol(),Period(),0,Bars(Symbol(),Period()),Candle); double BuyHedge=Bid-HedgeNow*Pips2(); double SellHedge=Bid+HedgeNow*Pips2(); if(Candle[1].close<Candle[1].open) { Sell=trade.Sell(0.01,Symbol(),Bid,0,0,"TestHedge"); } if(Candle[1].close>Candle[1].open) { Buy=trade.Buy(0.01,Symbol(),Ask,0,0,"TestHedge"); } } void OnTick() { if(NumberOfOrders()<1){Trade();} else if(NumberOfOrders()<2){Hedge();} }
Is this what you meant,tried change it to following but does not open a sell trade in the opposite direction
if(Buy>0&&BuyHedge) { //Buy } if(Sell>0&&SellHedge) { //Sell }
Obviously it is the same problem. You did not separate the code, and you also did not show any changes in OnTick().
I separated as you stated before, this time no sell trade of opening at all:
void Trade() { double Ask=SymbolInfoDouble(Symbol(),SYMBOL_ASK); double Bid=SymbolInfoDouble(Symbol(),SYMBOL_BID); MqlRates Candle[]; ArraySetAsSeries(Candle,true); int rates=CopyRates(Symbol(),Period(),0,Bars(Symbol(),Period()),Candle); double BuyHedge=Bid-HedgeNow*Pips2(); double SellHedge=Bid+HedgeNow*Pips2(); if(Candle[1].close<Candle[1].open) { Buy=trade.Buy(0.01,Symbol(),Ask,0,0,"TestHedge"); } else if(Buy>0&&BuyHedge) { Sell=trade.Sell(0.01,Symbol(),Bid,0,0,"TestHedge"); } }
Ontick function i tried adding else if as my previous post but still the same as open buy & sell at the same time
void OnTick() { if(NumberOfOrders()<1){Trade();} }
I tried modifying that would not work out made changes but still opens at the same time instead of 10 pips apart.
void Trade() { double Ask=SymbolInfoDouble(Symbol(),SYMBOL_ASK); double Bid=SymbolInfoDouble(Symbol(),SYMBOL_BID); MqlRates Candle[]; ArraySetAsSeries(Candle,true); int rates=CopyRates(Symbol(),Period(),0,Bars(Symbol(),Period()),Candle); double BuyHedge=Bid-HedgeNow*Pips2(); double SellHedge=Bid+HedgeNow*Pips2(); if(Candle[1].close<Candle[1].open) { Buy=trade.Buy(0.01,Symbol(),Ask,0,0,"TestHedge"); } if(Buy>0) { if(Bid>BuyHedge) { Sell=trade.Sell(0.01,Symbol(),Bid,0,0,"TestHedge"); } } if(Candle[1].close>Candle[1].open) { Sell=trade.Sell(0.01,Symbol(),Bid,0,0,"TestHedge"); } if(Sell>0) { if(SellHedge<Bid) { Buy=trade.Buy(0.01,Symbol(),Ask,0,0,"TestHedge"); } } }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I want to hedge but my ea will only open trades both(buy & sell) at the same instead of 10 pips.
please help if you know the problem