How to code? - page 201

 

How to improve these results?!

Hi,

I'm writing my first EA which partially shows nice numbers in back testing. However, I can't figure out how to improve the bad parts.

Firstly, it has a high winning percentage of 86% however only a small profit factor because the losing trades loose much more than the winners win!

I have a MM in place which does not use more than 5% of the account balance per trade and over all active trade not more than 11% of the account balance can be used. Also I trail all stop losses.

It seems that I'm closing (OrderClose) the winning trades too early and cut the losing trades too late (or S/L them).

What is a good strategy for that? I implemented something like "don't close winning trades even if there's a closebuy signal" but that did not work out better either!

Would appreciate any tips! The full report can be found here.

 

easiest way to add a 3 pip TP for every manual trade?

i need to add a 3 pip take profit on the forex for every manually entered trade. what is the easiest way to do this? i have no programming skills and can not find any default value to set in metatrader 4's options.

 

Reseting the buy stop order

Hi,

I have written this code and although it compiles it does not work. (Meaning it does not delete the buystop)

I was thinking there might be something wrong with the "for" statement but I am pretty new so I am not sure.

If someone could point me to the problem, I would really appreciate it.

thanks

if( StopResetMinutes > 0)

{

total = OrdersTotal();

if(total>0)

for(i=0;i<total;i++)

{

OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

if(OrderType()==OP_BUY && OrderSymbol()==Symbol())

{

if((TimeCurrent() - OrderOpenTime()) /60 > StopResetMinutes ) OrderDelete(OrderTicket());

{

if(PrintComments) Print("Buy Stop Deleted.");

}

}

}

}

 
asgard2:
Hi,

I have written this code and although it compiles it does not work. (Meaning it does not delete the buystop)

I was thinking there might be something wrong with the "for" statement but I am pretty new so I am not sure.

If someone could point me to the problem, I would really appreciate it.

thanks

if( StopResetMinutes > 0)

{

total = OrdersTotal();

if(total>0)

for(i=0;i<total;i++)

{

OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

if(OrderType()==OP_BUY && OrderSymbol()==Symbol())

{

if((TimeCurrent() - OrderOpenTime()) /60 > StopResetMinutes ) OrderDelete(OrderTicket());

{

if(PrintComments) Print("Buy Stop Deleted.");

}

}

}

}

[/code]

[CODE] if( StopResetMinutes > 0)

{

total = OrdersTotal();

if(total>0)

for(i=0;i<total;i++)

{

OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

if(OrderType()==OP_BUYSTOP && OrderSymbol()==Symbol())

{

if((TimeCurrent() - OrderOpenTime()) /60 > StopResetMinutes )

{

OrderDelete(OrderTicket());

if(PrintComments) Print("Buy Stop Deleted.");

}

}

}

}
 
asgard2:
Hi,

I have written this code and although it compiles it does not work. (Meaning it does not delete the buystop)

If you want to close BUY or SELL orders, you have to use OrderClose() function.

 
okfar:

if(OrderType()==OP_BUYSTOP && OrderSymbol()==Symbol())

{

if((TimeCurrent() - OrderOpenTime()) /60 > StopResetMinutes )

{

OrderDelete(OrderTicket());

if(PrintComments) Print("Buy Stop Deleted.");

}

}

}

}

You know, I have been working on this for two days and you solved it in a few seconds..

Thankyou Thankyou Thankyou.. Thankyou and Thankyou..

I hope I sound grateful because I am stoked!

cheers

 

Dear all,

I have a simple question, I think.

I have an indicator that notifies me with a pop-up (alert) and I wanted to add a custom sound (other than the standard alert.wav).

I have noticed that once the event happens and the alert appears, no matter what "custom" sound I programmed in the indicator, Metatrader 4 will ALWAYS play the sound I have assigned for alert (default this is alert.wav, see the MT4 menu Tools>Options>Events).

Is it possible to program the indicator in such a manner that I both get a visual alert AND a custom assigned audible alert...?

Many thanks in advance..!

 

Actually, you can take any sound and call it alert.wav and replace the original file.

 

Changing custom Alert

Snowski:
Dear all,

I have a simple question, I think.

I have an indicator that notifies me with a pop-up (alert) and I wanted to add a custom sound (other than the standard alert.wav).

I have noticed that once the event happens and the alert appears, no matter what "custom" sound I programmed in the indicator, Metatrader 4 will ALWAYS play the sound I have assigned for alert (default this is alert.wav, see the MT4 menu Tools>Options>Events).

Is it possible to program the indicator in such a manner that I both get a visual alert AND a custom assigned audible alert...?

Many thanks in advance..!

Hello Snowski,

Try............

if (alert_ON == true) // to turn on or turn off sound alert

{

Alert ("Key in you custom PopUp Here",Symbol(),"-",TimeFrame);

PlaySound("custom.wav");

}

I am not so good at coding but you can try this as it should work. the custom .wav, you can enter your own file name into the ("??????.wav")

if you want to be able to set alert on and off, you need to also add

extern bool alert_ON = True; // or false at the beginning of your indicator code

 

History function

Hi,

I have this code below. I am trying to implement a delay between my buystop orders in the event they were deleted. I have never used the history function before.

I am unable to compile it because of an unbalanced parentheses error, can anyone tell me why these are unbalanced?

Also, can anyone tell me if I am on the right track or if I should be looking at another way to do this?

if ((type == _OP_BUYSTOP) && (MayOpenDeferOrder && NextBuyStop_Order_Minutes !=0))//Time Delay for the next Buy Stop Order

int hstTotal=OrdersHistoryTotal();

for(i=0;i<hstTotal;i++)

{

if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false)

Print("Access to history failed (",GetLastError(),")"); break;

{

if (OrderDelete() && (((TimeCurrent() - OrderCloseTime())/60) =< NextBuyStop_Order_Minutes) MayOpenDeferOrder = false;

}

}

Thanks

Reason: