Universal MA Cross EA - page 105

 
sachin_syd:
Dear Mrtools/Mladen

Cud u plz set the max distance parameter to be distance of closing price of a bar from the slow ma

the curr setting is meaningless imho

Thanks

Sachin

Sachin

Simply find the line that goes like this :

MaxDistance = MathFloor(MathAbs((FastMACurrent-SlowMACurrent)/pPoint));

and replace the FastMACurrent with either Close[1] (for the close of first closed bar) or Close[0] (for the close of the still opened bar)

 

ok i have done that now testing..cheers

cud u plz also assist here : https://www.mql5.com/en/forum/general

mladen:
Sachin

Simply find the line that goes like this :

MaxDistance = MathFloor(MathAbs((FastMACurrent-SlowMACurrent)/pPoint));

and replace the FastMACurrent with either Close[1] (for the close of first closed bar) or Close[0] (for the close of the still opened bar)
 

Dear Mladen cud u please check why time filter isn't working . see red vertical lines on chart where it is not supposed to trade but traded. In Ea i set trade only certain hours. Many Thanks

mladen:
Sachin

Simply find the line that goes like this :

MaxDistance = MathFloor(MathAbs((FastMACurrent-SlowMACurrent)/pPoint));

and replace the FastMACurrent with either Close[1] (for the close of first closed bar) or Close[0] (for the close of the still opened bar)
Files:
untitled.png  28 kb
untitled_1.png  29 kb
 

Hi Mladen,

I could not compile mql4 code because of following errors:

extern string Pivot.Setting = "---------- Pivot Filter Setting";

extern bool Use.Pivot.Filter = false;

==> '.' - semicolon expected MACrossEAV1.5.mq4 77 28 if(Use.Pivot.Filter==true)

==> 'Use' - undeclared identifier MACrossEAV1.5.mq4 458 7

'Pivot' - struct or class type expected MACrossEAV1.5.mq4 458 11

'Filter' - struct or class type expected MACrossEAV1.5.mq4 458 17

What did I do wrong?

Thanks for your help

 
StephFX:
Hi Mladen,

I could not compile mql4 code because of following errors:

extern string Pivot.Setting = "---------- Pivot Filter Setting";

extern bool Use.Pivot.Filter = false;

==> '.' - semicolon expected MACrossEAV1.5.mq4 77 28 if(Use.Pivot.Filter==true)

==> 'Use' - undeclared identifier MACrossEAV1.5.mq4 458 7

'Pivot' - struct or class type expected MACrossEAV1.5.mq4 458 11

'Filter' - struct or class type expected MACrossEAV1.5.mq4 458 17

What did I do wrong?

Thanks for your help

StephFX

Remove the "." from the variable name

You can replace it with "_" for example and then you will have :

extern string Pivot_Setting = "---------- Pivot Filter Setting";

extern bool Use_Pivot_Filter = false;

and this

if(Use_Pivot_Filter==true)

and then all will compile OK

 

Hi everybody,

Since I am trying out a martingale strategy, I tried to make it so that "STOP AND REVERSE" only works when the last trade was a win.

int histotal=OrdersHistoryTotal(); if (histotal>0)

{

for(int count=histotal-1;count>=0;count--)

{

if(OrderSelect(count,SELECT_BY_POS,MODE_HISTORY))

{

if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)

{

if(OrderProfit()>0)

{

if(StopAndReverse==true && subTotalTrade()>0)

{

if((LastTrade=="BUY" && SellCondition==true) || (LastTrade=="SELL" && BuyCondition==true))

{

subCloseOrder();

if(subTotalTrade()>0) subCloseOrder();

if(subTotalTrade()>0) subCloseOrder();

if(IsTesting() && PrintControl==true) Print("STOP AND REVERSE !");

}

}

}

}

}

}

}

It doesn't seem to be working, however. It will stop and reverse even if the last trade was a loss. Any suggestions?

Thanks!

 
BlackCoq:
Hi everybody,

Since I am trying out a martingale strategy, I tried to make it so that "STOP AND REVERSE" only works when the last trade was a win.

It doesn't seem to be working, however. It will stop and reverse even if the last trade was a loss. Any suggestions?

Thanks!

You are not checking the time of the order. You must check the close time of the order too, and the order with the greatest close time is the one you want to check for profit

 
mladen:
You are not checking the time of the order. You must check the close time of the order too, and the order with the greatest close time is the one you want to check for profit

The thing is I use a very similar code for the martingale system which works perfectly:

//|---------martingale

int martingalefactor()

{

int histotal=OrdersHistoryTotal();

if (histotal>0)

{

for(int cnt=histotal-1;cnt>=0;cnt--)

{

if(OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY))

{

if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)

{

if(OrderProfit()<0)

{

lotsfactor=lotsfactor*multiplier;

return(lotsfactor);

}

else

{

lotsfactor=initiallotsfactor;

if(lotsfactor<=0)

{

lotsfactor=1;

}

return(lotsfactor);

}

}

}

}

}

return(lotsfactor);

}

Since it works for martingale, shouldn't it work now also?

 
BlackCoq:
The thing is I use a very similar code for the martingale system which works perfectly: Since it works for martingale, shouldn't it work now also?

Try using something like this :

double GetLastPL()

{

double TempLastOrderProfit = 0;

datetime CloseTime = 0;

for(int i=OrdersHistoryTotal()-1;i>=0;i--)

{

if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))

if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderCloseTime()>CloseTime)

{

CloseTime = OrderCloseTime();

TempLastOrderProfit = OrderProfit() + OrderSwap()+ OrderCommission();

}

}

return(TempLastOrderProfit);

}

It will return you the exact amount of the profit (or loss) of the last order

 
mladen:
Try using something like this : It will return you the exact amount of the profit (or loss) of the last order

Thank you for you're help, Mladen. I tweaked with the code a little until I got it compiling without any errors, but the EA still stops and reversed after a loss. This is the exact code I'm using now:

{

double TempLastOrderProfit = 0;

datetime CloseTime = 0;

for(int i=OrdersHistoryTotal()-1;i>=0;i--)

{

if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))

if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderCloseTime()>CloseTime)

{

CloseTime = OrderCloseTime();

}

}

if(StopAndReverse==true && subTotalTrade()>0 && OrderProfit()>0)

{

if((LastTrade=="BUY" && SellCondition==true) || (LastTrade=="SELL" && BuyCondition==true))

{

subCloseOrder();

if(subTotalTrade()>0) subCloseOrder();

if(subTotalTrade()>0) subCloseOrder();

if(IsTesting() && PrintControl==true) Print("STOP AND REVERSE !");

}

}

}

double GetLastPL() Gives me the following error: '(' - function definition unexpected.

Reason: