How to code? - page 283

 

Mathmatical Expectation Help Please

Hello

I seem to have snookered myself to a degree.

I am trying to use an expectation formular within my EA I have the formular 1-avgwin/avgloss*system accuracy+1 and that works fine, but I would like to know how to calculate the and display the difference between the Order and the StopLoss e.g.

OP_SELLSTOP 1.63406

StopLoss 1.63603

1.63406 - 1.63603 = -0.00197 I think this needs to be a positive number.

An expectation of 1.45

So in order to calculate the TakeProfit -0.00197 * 1.45 = -0.00285

Place TP at OP_SELLSTOP 1.63406 - 1.63121

and vice versa for the Long position

its all part of this thread https://www.mql5.com/en/forum/178980 and if you have a look at the excel sheet you will see I am just about there.

Any help would be great.

Cheers Beno

 
Beno:
Hello

I seem to have snookered myself to a degree.

I am trying to use an expectation formular within my EA I have the formular 1-avgwin/avgloss*system accuracy+1 and that works fine, but I would like to know how to calculate the and display the difference between the Order and the StopLoss e.g.

OP_SELLSTOP 1.63406

StopLoss 1.63603

1.63406 - 1.63603 = -0.00197 I think this needs to be a positive number.

An expectation of 1.45

So in order to calculate the TakeProfit -0.00197 * 1.45 = -0.00285

Place TP at OP_SELLSTOP 1.63406 - 1.63121

and vice versa for the Long position

its all part of this thread https://www.mql5.com/en/forum/178980 and if you have a look at the excel sheet you will see I am just about there.

Any help would be great.

Cheers Beno

The simplest way is not thinking about that and use:

double MathAbs(double value)

MathAbs - MQL4 Documentation

Regards

 

Hi CRN

Thanks for the reply this is what I have been trying

double PipSL = MathAbs (OrderOpenPrice() - StopLoss); Print (MathAbs (OrderOpenPrice() - StopLoss));

I think its right but is just prints PipSL 15769.68328362

1 2011.01.04 00:00 sell stop 1 0.01 1.54279 0.00000 0.00000 0.00 10000.00

2 2011.01.07 08:20 sell 1 0.01 1.54279 0.00000 0.00000 0.00 10000.00

3 2011.01.07 08:20 modify 1 0.01 1.54279 1.57712 0.00000 0.00 10000.00

4 2011.01.11 23:40 close at stop 1 0.01 1.56045 1.57712 0.00000 -17.66 9982.34

and I require the actual difference between the sell and the SL

 

Somebody please help me.

Hello and Happy's Christmas for all.

Firstly I'm newcomer to this forum.I got problem with with Ea and can somebody fix's it up for me? The problem is how to set this EA for real trading and the EA just gray colour on my live trade.

Here the attachment :

spielershedge_library.mqh

spielershedge_pipstar.mq4

spielershedge_ea_v2.8.1.ex4

spielershedge_divergence_v5.1.ex4

-although it was old ea but I think maybe we can share and take something that will benefit to all of us.

-i just found this from Hedge trading spieler system derived from futures spread trading - Page 193 @ Forex Factory ( SpielersHedge PipStar.mq4 ) and the rest from Hedge trading spieler system derived from futures spread trading - Page 87 @ Forex Factory

-Sorry for my bad english.

P/S : I'm very appreciate for lesson, guides, comments, and criticism from all of you for my improvement. I believed the more we give our knowledge, the mores we gain the knowledge.

 
Beno:
Hi CRN

Thanks for the reply this is what I have been trying

double PipSL = MathAbs (OrderOpenPrice() - StopLoss); Print (MathAbs (OrderOpenPrice() - StopLoss));

I think its right but is just prints PipSL 15769.68328362

1 2011.01.04 00:00 sell stop 1 0.01 1.54279 0.00000 0.00000 0.00 10000.00

2 2011.01.07 08:20 sell 1 0.01 1.54279 0.00000 0.00000 0.00 10000.00

3 2011.01.07 08:20 modify 1 0.01 1.54279 1.57712 0.00000 0.00 10000.00

4 2011.01.11 23:40 close at stop 1 0.01 1.56045 1.57712 0.00000 -17.66 9982.34

and I require the actual difference between the sell and the SL

If You need actual use iClose(0,0,0)-OrderStopLoss().

but first select right order by OrderSelect;

Regards

 

Time Filter with CloseAll Help Please

Gidday

I have a Time Filter working on the EA but I have been trying to attach a closeall to it so if the time equals the close time then closeall open positions

extern string timefilter="Time Filter";

extern int gmtshift=1; // gmt offset of the broker

extern bool generalfilter=false; // enable time filter

extern int starthour=7; // start hour to trade after this hour

extern int startminutes=0; // minutes of the start hour

extern int endhour=21; // stop to trade after this hour

extern int endminutes=0; // minutes of the start hour

extern bool tradesunday=true; // trade on sunday

extern bool fridayfilter=false; // enable special time filter on friday

extern int fridayhour=21; // stop to trade after this hour

extern int fridayminutes=0; // minutes of the friday hour[/CODE]

[CODE]void start() {

if(generalfilter){

nstarthour=starthour+(gmtshift);if(nstarthour>23)nstarthour=nstarthour-24;

if(nstarthour<10)istarthour="0"+nstarthour;

if(nstarthour>9)istarthour=nstarthour;

if(startminutes<10)istartminutes="0"+startminutes;

if(startminutes>9)istartminutes=startminutes;

tstart=StrToTime(istarthour+":"+istartminutes);

nendhour=endhour+(gmtshift);if(nendhour>23)nendhour=nendhour-24;

if(endhour<10)iendhour="0"+nendhour;

if(endhour>9)iendhour=nendhour;

if(endminutes<10)iendminutes="0"+endminutes;

if(endminutes>9)iendminutes=endminutes;

tend=StrToTime(iendhour+":"+iendminutes);

}

if(fridayfilter){

nfridayhour=fridayhour+(gmtshift);if(nfridayhour>23)nfridayhour=nfridayhour-24;

if(nfridayhour<10)ifridayhour="0"+nfridayhour;

if(nfridayhour>9)ifridayhour=nfridayhour;

if(fridayminutes<10)ifridayminutes="0"+fridayminutes;

if(fridayminutes>9)ifridayminutes=fridayminutes;

tfriday=StrToTime(ifridayhour+":"+ifridayminutes);

}

if((generalfilter && (nstarthour<nendhour && TimeCurrent()tend) || (nstarthour>nendhour && TimeCurrent()tend))

|| (tradesunday==false && DayOfWeek()==0) || (fridayfilter && DayOfWeek()==5 && TimeCurrent()>tfriday))return(0);

if (TimeCurrent() >= tend) {

for (int i=OrdersTotal()-1; i>=0; i--) {

if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {

if (OrderSymbol()==TradeSymbol) {

if (OrderType()==OP_BUY) {

pBid=MarketInfo(OrderSymbol(), MODE_BID);

OrderClose(OrderTicket(), OrderLots(), Bid, slippage, Yellow);

}

if (OrderType()==OP_SELL) {

pAsk=MarketInfo(OrderSymbol(), MODE_ASK);

OrderClose(OrderTicket(), OrderLots(), Ask, slippage, Orange);

}

}

}

}

}
 

please help me

extern int BuyStopTakeProfit=10;

extern int BuyStopSL=1000;

how to code

if BuyStopTakeProfit Hit TakeProfit, Delete All Pending Order

please anyone can help

 

Help!!!! Please!!!! iCustom function

Help,

I have tried everything to get my C_EA_rev6.mq4 to call the any buffer from the custom indicator VSATEXTSIGNALS.mq4. I used the iCustom function but it always returns 2147483647 which I understand is an error code. The custom indicator places text signals on the chart based on volume spread analysis techniques. The custom indicator runs fine when I attach it to a chart. I have spent countless hours on this and tried every combination I know. Any help would be greatly appreciated. Also, I have a question, can you use the iCustom function on a custom indicator that calls a script or .dll file?

See attachments for code to indicator and EA.

Thanks,

cmfxtrader

Files:
 
cmfxtrader:
Help,

I have tried everything to get my C_EA_rev6.mq4 to call the any buffer from the custom indicator VSATEXTSIGNALS.mq4. I used the iCustom function but it always returns 2147483647 which I understand is an error code. The custom indicator places text signals on the chart based on volume spread analysis techniques. The custom indicator runs fine when I attach it to a chart. I have spent countless hours on this and tried every combination I know. Any help would be greatly appreciated. Also, I have a question, can you use the iCustom function on a custom indicator that calls a script or .dll file?

See attachments for code to indicator and EA.

Thanks,

cmfxtrader

Hey,

The thing is that while you are trying to read buffer from the indicator it outputs text messages, which are not buffers. Thus why you are getting 2147483647 value which is EMPTY_VALUE not an error.

Anyway I guess you would like to automate signals from this indicator. There is a simple solution for that. The indicator is declared to have 7 buffers (#property indicator_buffers 7) but it is using only 5. Indicators can use max 8 buffers. It means that you can declare another additional buffer just for your calculations and fill it with messages identifies. You will find message numbers in TextOutput function. Simply add numbers to your buffer depends which message is displayed. For example if text is : "UPTHRUST / Weakness_" then add 1 to your buffer, if message is PSEUDO UPTHRUST / Weakness_ then add 4 and so on. The index of the buffer will be the same as value from "i" variable.

As for your second question : you can allways use iCustom function for an indicator (not script) and read the values if it fill buffers declared in the indicator. For example if this will be indicator that draws lines then you can read the lines values - because to draw something (except labels) indicator have to fill buffers. If the indicator will be creating graphic objects (like the one you attached) then you will need to : a) read values from graphic objects, or b) recode indicator (like I suggested above). It does not matter if the indicator is using DLL or not - it just need to fill buffer properly to read it's values from iCustom function.

 
Beno:
Gidday

I have a Time Filter working on the EA but I have been trying to attach a closeall to it so if the time equals the close time then closeall open positions

extern string timefilter="Time Filter";

extern int gmtshift=1; // gmt offset of the broker

extern bool generalfilter=false; // enable time filter

extern int starthour=7; // start hour to trade after this hour

extern int startminutes=0; // minutes of the start hour

extern int endhour=21; // stop to trade after this hour

extern int endminutes=0; // minutes of the start hour

extern bool tradesunday=true; // trade on sunday

extern bool fridayfilter=false; // enable special time filter on friday

extern int fridayhour=21; // stop to trade after this hour

extern int fridayminutes=0; // minutes of the friday hour[/CODE]

[CODE]void start() {

if(generalfilter){

nstarthour=starthour+(gmtshift);if(nstarthour>23)nstarthour=nstarthour-24;

if(nstarthour<10)istarthour="0"+nstarthour;

if(nstarthour>9)istarthour=nstarthour;

if(startminutes<10)istartminutes="0"+startminutes;

if(startminutes>9)istartminutes=startminutes;

tstart=StrToTime(istarthour+":"+istartminutes);

nendhour=endhour+(gmtshift);if(nendhour>23)nendhour=nendhour-24;

if(endhour<10)iendhour="0"+nendhour;

if(endhour>9)iendhour=nendhour;

if(endminutes<10)iendminutes="0"+endminutes;

if(endminutes>9)iendminutes=endminutes;

tend=StrToTime(iendhour+":"+iendminutes);

}

if(fridayfilter){

nfridayhour=fridayhour+(gmtshift);if(nfridayhour>23)nfridayhour=nfridayhour-24;

if(nfridayhour<10)ifridayhour="0"+nfridayhour;

if(nfridayhour>9)ifridayhour=nfridayhour;

if(fridayminutes<10)ifridayminutes="0"+fridayminutes;

if(fridayminutes>9)ifridayminutes=fridayminutes;

tfriday=StrToTime(ifridayhour+":"+ifridayminutes);

}

if((generalfilter && (nstarthour<nendhour && TimeCurrent()tend) || (nstarthour>nendhour && TimeCurrent()tend))

|| (tradesunday==false && DayOfWeek()==0) || (fridayfilter && DayOfWeek()==5 && TimeCurrent()>tfriday))return(0);

if (TimeCurrent() >= tend) {

for (int i=OrdersTotal()-1; i>=0; i--) {

if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {

if (OrderSymbol()==TradeSymbol) {

if (OrderType()==OP_BUY) {

pBid=MarketInfo(OrderSymbol(), MODE_BID);

OrderClose(OrderTicket(), OrderLots(), Bid, slippage, Yellow);

}

if (OrderType()==OP_SELL) {

pAsk=MarketInfo(OrderSymbol(), MODE_ASK);

OrderClose(OrderTicket(), OrderLots(), Ask, slippage, Orange);

}

}

}

}

}

try to check this part:

if((generalfilter && (nstarthour<nendhour && TimeCurrent()tend) || (nstarthour>nendhour && TimeCurrent()tend))

|| (tradesunday==false && DayOfWeek()==0) || (fridayfilter && DayOfWeek()==5 && TimeCurrent()>tfriday))return(0);

the other part of the code could be easier, but it should be working.

However, if you will exit from script before close all part then it wont work, and it seems that the script is doing that.

Take a look this part for example:

(fridayfilter && DayOfWeek()==5 && TimeCurrent()>tfriday) return(0);

In english it means: if it is friday, and friday filter is ON, and the TimeMark was passed (eg. end time is 18.00 and it is 18.01) then return(0).

It should be : if it is friday, and friday filter is ON, and the TimeMark was passed CLOSE ALL and (eg. end time is 18.00 and it is 18.01) then return(0).