Michel
476
Michel  
Dave137:
void TrailingPositions() {

double pBid, pAsk, pp;

pp = MarketInfo(OrderSymbol(), MODE_POINT);

if (OrderType()==OP_BUY) {

pBid = MarketInfo(OrderSymbol(), MODE_BID);

//BreakEven routine

if (BreakEven>0) {

if ((pBid-OrderOpenPrice())>BreakEven*pp) {

if ((OrderStopLoss()-OrderOpenPrice())<0) {

ModifyStopLoss(OrderOpenPrice()+0*pp);

}

}

}

if (TrailingStop>0) {

if ((pBid-OrderOpenPrice())>TrailingStop_Over135*pp){ //15 pips TS

ModifyStopLoss(pBid-TrailingStop_Over135*pp);

if (pBid-OrderOpenPrice()>TrailingStop_Over90*pp && pBid-OrderOpenPrice()<TrailingStop_Over135*pp){ //55 pips TS

ModifyStopLoss(pBid-TrailingStop_Over90*pp);

if ((OrderOpenPrice()-pAsk)>TrailingStop +TrailingStep+1*pp && (OrderOpenPrice()-pAsk) < TrailingStop_Over90*pp+TrailingStep-1*pp || OrderStopLoss()==0) {//75 pips TS

ModifyStopLoss(pAsk+TrailingStop*pp);

return;

}

}

}

}

}[/PHP]

Three levels of Trailing Stop:

1) 75 Pips TS up to first 90 Pips Profit.

2) 55 Pips TS after 90 but only up to 135 pips profit.

3) 15 Pips TS after 135 pips profit.

The problem I am having is the Trailing Stop moves both up and down as the price moves up and down . . It should just be moving up as the price profit increases and stop if the price starts dropping! How do I get it to stop moving down as the price drops - The Trailing Stop is acting like a Yo-Yo as the price moves up and down.

I am not sure how to stop this from happening?? Please, I need your expertise!

Humbly,

Dave

for example:[PHP]ts = pBid - TrailingStop_Over135*pp;

if (ts > OrderOpenPrice() && ts > OrderStopLoss()) ModifyStopLoss(ts);

solamax
25
solamax  

please may i ask for help

Can I ask anybody to have a look at my code to see where it's wrong please....I am not much of a programmer and would appreciate some assistance with this.

many thanks in advance

also i just realized something - theres a guy called Ben Taylor selling an EA that looks almost exactly like the one that coder's guru programmed - maybe thats one of his clients - lol

if its not - we should let coders guru know about this

Files:
yyc196
511
yyc196  
Michel:
If needed, check first that you are later than 8 am:
if(Hour() < 8) return;[/PHP]

Then, find the max and min of the current day. (if its ok for you, its easier than from 8 am): [PHP]double Max = iHigh(Symbol(), PERIOD_D1, 0);

double Min = iLow(Symbol(), PERIOD_D1, 0);

int Range = (Max - Min) / Point;

if(Range > 90) return;

...

Hi Michel:

I refer to your code:

if(Hour() < 8) return;

I modified the code as follow:

if(Hour()>12) hr_x=1;

.....

.....

.....

.....

if(hr_x==1) signal=50;

But I had all the histogram bar 50!!!!

If you look at the chart below, it seem that the "Hour" command does not recognise it!!!

FYI, I am using 30 min chart, will there be a different. I tried to switch to 1Hour chart but the problem still exist!

I also tried "if(Hour() < 8) return; " but all the bar gone!!!

I tried many things but still cannot get it works.

Possible to advise me again? Thanks

Files:
untitled_5.jpg  115 kb
n3sve1k4s
47
n3sve1k4s  
n3sve1k4s:
Hi codersguru could you add signal with pop-up and arrows to indicator below?

can anyone add a signal???

Dave137
212
Dave137  

Thank you Michel for the proper fix to my triple Trailing Stop coding. This will hopefully put the final fix to my new ea creation. Without the generosity of everybody's knowledge, I would not of been able to program this language. I keep notes on all the new information I acquire on this language. I hope when MT5 gets introduced, the coding will not change to radically - I would hate to start all over again! Thanks again!!

Dave

<<<

Dave137
212
Dave137  
solamax:

Can I ask anybody to have a look at my code to see where it's wrong please....I am not much of a programmer and would appreciate some assistance with this.

many thanks in advance

also i just realized something - theres a guy called Ben Taylor selling an EA that looks almost exactly like the one that coder's guru programmed - maybe thats one of his clients - lol

if its not - we should let coders guru know about this
double Buy2_1 = iOpen(NULL, 0, Current + 0); //Statement in question for crossover! double Buy2_2 = iMA(NULL, 0, 50, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

If I had to zero into a problem area, it would be this code above. There needs to be a cross over for a buy and a sell.

double Buy1_1 = iMA(NULL, 0, 5, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Buy1_2 = iMA(NULL, 0, 5, 0, MODE_EMA, PRICE_CLOSE, Current + 1); //1-Back

double Buy2_1 = iMA(NULL, 0, 50, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Buy2_2 = iMA(NULL, 0, 50, 0, MODE_EMA, PRICE_CLOSE, Current + 1); //1-Back

double Sell1_1 = iMA(NULL, 0, 5, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Sell1_2 = iMA(NULL, 0, 5, 0, MODE_EMA, PRICE_CLOSE, Current + 1); //1-Back

double Sell2_1 = iMA(NULL, 0, 50, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Sell2_2 = iMA(NULL, 0, 50, 0, MODE_EMA, PRICE_CLOSE, Current + 1); //1-Back

if(Buy1_1>Sell2_1 && Buy1_2<Sell2_2) Then Buy; // Proper 'UP' crossover has occurred!

if(Sell1_1Buy2_2) Then Sell; // Proper 'DOWN' crossover has occurred!

Dave

Dave137
212
Dave137  

This is not quite what you are looking for, but look it over anyway. Attach to another graph and it monitors all profit, loss from graphs that have working ea's on them.

solamax
25
solamax  

Dave - you're a blessing:)

Dave137:
double Buy2_1 = iOpen(NULL, 0, Current + 0); //Statement in question for crossover! double Buy2_2 = iMA(NULL, 0, 50, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

If I had to zero into a problem area, it would be this code above. There needs to be a cross over for a buy and a sell.

double Buy1_1 = iMA(NULL, 0, 5, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Buy1_2 = iMA(NULL, 0, 5, 0, MODE_EMA, PRICE_CLOSE, Current + 1); //1-Back

double Buy2_1 = iMA(NULL, 0, 50, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Buy2_2 = iMA(NULL, 0, 50, 0, MODE_EMA, PRICE_CLOSE, Current + 1); //1-Back

double Sell1_1 = iMA(NULL, 0, 5, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Sell1_2 = iMA(NULL, 0, 5, 0, MODE_EMA, PRICE_CLOSE, Current + 1); //1-Back

double Sell2_1 = iMA(NULL, 0, 50, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Sell2_2 = iMA(NULL, 0, 50, 0, MODE_EMA, PRICE_CLOSE, Current + 1); //1-Back

if(Buy1_1>Sell2_1 && Buy1_2<Sell2_2) Then Buy; // Proper 'UP' crossover has occurred!

if(Sell1_1Buy2_2) Then Sell; // Proper 'DOWN' crossover has occurred!

Dave

many thanks indeed - i will give it a go

WNW
632
WNW  

Coding help needed

Any help appreciated..

This would go in an EA as a component of the trade-closure routine.

I need to create a variable that always returns the highest historic balance of the account. I think this would require an array?

In practical terms, the language would be saying. "if my open profit is X-pips higher than the all-time high balance in the account, close all trades."

If someone can help with the variable I think I can code the rest.

Thanks in advance.

WNW
632
WNW  

Thanks for your reply, but you're right, they're not exactly what I'm looking for.

I don't have the code savvy yet to address the problem.

I need the code to return the "high watermark" of the account balance.

Thanks again, any help appreciated.

Dave137:
This is not quite what you are looking for, but look it over anyway. Attach to another graph and it monitors all profit, loss from graphs that have working ea's on them.