# Thread: Sorry Funyoo I Have A Problem

1. ## Sorry Funyoo I Have A Problem

Hi Funyoo
sorry but I can't do to code the situation that I attach you.
If the EMA 40 is below EMA 80 I go only short. I attempt the WPR should be above the level -20 (warning signal). When it falls back below the level of -20 I put an order SELLSTOP 5 pips below the close of the candle.
This is my code:

double Ema80=iMA(Symbol(),0,Ema1Period,0,Ema1Method,Ema1P rice,shift);
double Ema40=iMA(Symbol(),0,Ema2Period,0,Ema2Method,Ema2P rice,shift);

double WPR=iWPR(Symbol(),0,WPRPeriod,shift);
double WPRa=iWPR(Symbol(),0,WPRPeriod,shift+1);

int trend = 0;
if (Ema40>Ema80) trend = 1;
if (Ema40<Ema80) trend = 2;

bool ipercomprato = FALSE;
if(WPR<-20) ipercomprato = TRUE;

bool ipervenduto = FALSE;
if(WPR>-80) ipervenduto = TRUE;

int masignal=0;
if(trend==1 && ipervenduto)masignal=1;
if(trend==2 && ipercomprato)masignal=2;

But for me there is a mistake but I don't know where it is.

And this is the code for pending order:

if(masignal==1){

if(masignal==2){

if(hidestop==false&&sellstop>0){sl=Bid+sellstop*pt ;}else{sl=0;}
if(hidetarget==false&&selltarget>0){tp=Bid-selltarget*pt;}else{tp=0;}
if(martingale)ilots=NormalizeDouble(lots*martingal efactor(),2);else ilots=lots;
if(ilots<minlot)ilots=minlot;if(ilots>maxlot)ilots =maxlot;
RefreshRates();ticket=OrderSend(Symbol(),OP_SELLST OP,ilots,Bid-5*pt,slippage*mt,sl,tp,comment+". Magic: "+DoubleToStr(magic,0),magic,expire,Red);
if(ticket<=0){Print("Error Occured : "+errordescription(GetLastError()));}
else{tpb++;Print("Order opened : "+Symbol()+" Sell @ "+Bid+" SL @ "+sl+" TP @"+tp+" ticket ="+ticket);}
}
}
I used your template, of course.......

Davide

2. Hi paciola,

You should maybe replace this :

Code:
```bool ipercomprato = FALSE;
if(WPR<-20) ipercomprato = TRUE;

bool ipervenduto = FALSE;
if(WPR>-80) ipervenduto = TRUE;```
by :

Code:
```bool ipercomprato = FALSE;
if(WPRa>-20 WPR<-20) ipercomprato = TRUE;

bool ipervenduto = FALSE;
if(WPRa<-80 && WPR>-80) ipervenduto = TRUE;```
Then for the sl and tp, don't forget to replace Bid by Bid-5*pt. You should replace 5 by gap (as an integer) and then set the gap depending on your broker's stoplevel.

3. Many thanks Funyoo but it doesn't work and I don't Know why.
When you have time, can you see the code please?
I tell you which is the strategy.
First of all we determine the trend through the EMA's.
When EMA 40 is above the EMA 80 we go ONLY long, and when the EMA 40 is below the EMA 80 we go ONLY short.
The input signal is given by the WPR 21 periods.
Example;
if the trend is long we attempt that WPR goes in the oversold area (this is tha alert moment).
Then we attempt that WPR goes out to the oversold area (but can pass three or four o five candle in oversold area) and when the candle is closed we place to BUYSTOP order 5 pips up the close of last candle.
TP is 30 pips and stop loss 50 pip fix.

For sell order is the opposite situation.

There isn't any error in the code or in the journal, but the EA don't open any order.

Thanks Davide

4. Sorry I attached you the code of my EA

5. Originally Posted by paciola
Sorry I attached you the code of my EA
Hi paciola,

Here is the EA.

6. Thank you Funyoo now I study your code.
Many thanks

Davide