Coding help - page 159

 
mladen:
Don't change that part of code. That part of code is checking if your broker is 4 or 5 digit broker. Also, here is a test using a $500 for initial deposit (risk 5% stop loss 20 pips, EURUSD used for test) and it works even with that initial deposit too

Hi, Mladen.

Yesterday, have asked you about the order coding.

But it too Complex.

I'm sorry, because i want a simple coding.

Just like this:

Account balance $500

with a 5% risk , open lots= $0.25

lots=$500*(risk/100)

lots=$500*(0.05/100)

lots=$500(0.0005)

lots=$0.25

Just liked this EA auto open a $0.25 lots.

And the lots count don't Mixing with Stoploss or TProfit.

I hope you can help me to solve this problem.

Thank you very much.

extern double lots = 0.1;extern double stopsize = 20;

extern double profsize = 10;

extern double Risk =5;

int err;

int ticket;

double stop;

double prof;

int init() { return(0); }

int deinit() { return(0); }

int start()

{

int TotalOrders = 0;

for (int i=0; i <= OrdersTotal(); i++)

{

if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

if (OrderSymbol() == Symbol())

TotalOrders++;

}

if (TotalOrders<1)

{

double sl = stopsize*Point*MathPow(10,Digits%2);

double tp = profsize*Point*MathPow(10,Digits%2);

stop = (Ask-sl);

prof = (Ask+tp);

ticket = OrderSend(Symbol(), OP_BUY, getLots(sl,Risk), Ask, 3, 0, 0, NULL,LimeGreen);

OrderModify( ticket, OrderOpenPrice(), stop, prof, 0, Blue);

}

err=GetLastError();

Comment(" ");

}

//

//

//

//

//

double getLots(double stopLoss, double risk)

{

RefreshRates();

double pPoint = MarketInfo(Symbol(),MODE_POINT);

double step = MarketInfo(Symbol(),MODE_LOTSTEP);

double minLot = MarketInfo(Symbol(),MODE_MINLOT);

double maxLot = MarketInfo(Symbol(),MODE_MAXLOT);

double lots = minLot;

if (risk>0 && stopLoss>0)

{

lots = AccountFreeMargin()*(risk/100.0)/(stopLoss*MarketInfo(Symbol(),MODE_TICKVALUE)/pPoint);

}

return(MathMax(MathMin(lots,maxLot),minLot));

}
 
hock87:
Hi, Mladen.

Yesterday, have asked you about the order coding.

But it too Complex.

I'm sorry, because i want a simple coding.

Just like this:

Account balance $500

with a 5% risk , open lots= $0.25

lots=$500*(risk/100)

lots=$500*(0.05/100)

lots=$500(0.0005)

lots=$0.25

Just liked this EA auto open a $0.25 lots.

And the lots count don't Mixing with Stoploss or TProfit.

I hope you can help me to solve this problem.

Thank you very much.

extern double lots = 0.1;extern double stopsize = 20;

extern double profsize = 10;

extern double Risk =5;

int err;

int ticket;

double stop;

double prof;

int init() { return(0); }

int deinit() { return(0); }

int start()

{

int TotalOrders = 0;

for (int i=0; i <= OrdersTotal(); i++)

{

if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

if (OrderSymbol() == Symbol())

TotalOrders++;

}

if (TotalOrders<1)

{

double sl = stopsize*Point*MathPow(10,Digits%2);

double tp = profsize*Point*MathPow(10,Digits%2);

stop = (Ask-sl);

prof = (Ask+tp);

ticket = OrderSend(Symbol(), OP_BUY, getLots(sl,Risk), Ask, 3, 0, 0, NULL,LimeGreen);

OrderModify( ticket, OrderOpenPrice(), stop, prof, 0, Blue);

}

err=GetLastError();

Comment(" ");

}

//

//

//

//

//

double getLots(double stopLoss, double risk)

{

RefreshRates();

double pPoint = MarketInfo(Symbol(),MODE_POINT);

double step = MarketInfo(Symbol(),MODE_LOTSTEP);

double minLot = MarketInfo(Symbol(),MODE_MINLOT);

double maxLot = MarketInfo(Symbol(),MODE_MAXLOT);

double lots = minLot;

if (risk>0 && stopLoss>0)

{

lots = AccountFreeMargin()*(risk/100.0)/(stopLoss*MarketInfo(Symbol(),MODE_TICKVALUE)/pPoint);

}

return(MathMax(MathMin(lots,maxLot),minLot));

}

hock87

There is no simple(r) way to calculate lot size when equity, stop loss and required risk are taken into account. Also, you can not calculate the risk without knowing the stop loss (think about it : if you open an order, let say, size 1 lot and you close that after 1 pip or you close it after 100 pips the losses (and that way the risk that was taken) are not going to be the same and they can not be the same).

If you calculate it like that (without a known stop loss) then it is not the risk calculation but a simple lot size calculation (which does not imply any kind of risk calculation)

 
mladen:
hock87

There is no simple(r) way to calculate lot size when equity, stop loss and required risk are taken into account. Also, you can not calculate the risk without knowing the stop loss (think about it : if you open an order, let say, size 1 lot and you close that after 1 pip or you close it after 100 pips the losses (and that way the risk that was taken) are not going to be the same and they can not be the same).

If you calculate it like that (without a known stop loss) then it is not the risk calculation but a simple lot size calculation (which does not imply any kind of risk calculation)

Mladen, you are right.

I know It does not imply any kind of risk calculation.

and just want a simple lot size calculation,

let it auto calculation lot size with the account balance with %.

lots=$500*(risk%/100)

lots=$500*(0.05/100)

lots=$500(0.0005)

lots=$0.25

Just liked this EA auto open a $0.25 lots.

And the lots count don't Mixing with Stoploss or TProfit.

How to coding it?

Thanks.

 
hock87:
Mladen, you are right.

I know It does not imply any kind of risk calculation.

and just want a simple lot size calculation,

let it auto calculation lot size with the account balance with %.

lots=$500*(risk%/100)

lots=$500*(0.05/100)

lots=$500(0.0005)

lots=$0.25

Just liked this EA auto open a $0.25 lots.

And the lots count don't Mixing with Stoploss or TProfit.

How to coding it?

Thanks.

Try the way it is described by KimIV here : b-Lots

 

Thank a lot to mladen, i think is similar to what in my mind#1579, by the way, is it possible to convert DPO in the similar way as RSI or MFI equations normalize the vertical scale?Detrended Price Oscillator - MQL4 Code Base, thanks again.

 
kenwa:
Thank a lot to mladen, i think is similar to what in my mind#1579, by the way, is it possible to convert DPO in the similar way as RSI or MFI equations normalize the vertical scale?Detrended Price Oscillator - MQL4 Code Base, thanks again.

kenwa

Once when you have a template not difficult

Here is a rsi of a dpo. Upper is DPO and lower is the RSI of a DPO

Files:
 

hi mladen, i got your rsi of macd before, is it made with similar ways/logic as these recent force index FI and DPO ones?

i have attached your new rsi versions made recenlty(FI and DPO) on my computer, i encounter a problem if i use icustom function to recall their output values, it is not from 0 to 100 as show on chart but from -100 to 0 to 100, any comments of why, is it i refer recall wrongly the inside buffer value? thanks for advice.

Files:
 

Hi, Mladen.

I have problem ,

when the buy order open price move to Reverse direction and Distance market price over 25 point,

it auto open a buy order again.

How to coding this strategic?

Thanks.

extern double lots = 0.1;

extern double stopsize = 50;

extern double profsize = 20;

int err;

int ticket;

double stop;

double prof;

int start()

{

int TotalOrders = 0;

for (int i=0; i <= OrdersTotal(); i++)

{

if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

if (OrderSymbol() == Symbol())

TotalOrders++;

}

if (TotalOrders<1)

{

ticket=OrderSend(Symbol(), OP_Buy, 0.1, Ask, 3, 0, 0, NULL,LimeGreen);

stop=(Ask+stopsize*Point);

prof=(Ask-profsize*Point);

OrderModify( ticket, OrderOpenPrice(), stop, prof, 0, Blue);

}

err=GetLastError();

// Comment("This is a test ", err, " ", stop, " ", prof);

Comment(" ");

return(0);

}
 
hock87:
Hi, Mladen.

I have problem ,

when the buy order open price move to Reverse direction and Distance market price over 25 point,

it auto open a buy order again.

How to coding this strategic?

Thanks.

extern double lots = 0.1;

extern double stopsize = 50;

extern double profsize = 20;

int err;

int ticket;

double stop;

double prof;

int start()

{

int TotalOrders = 0;

for (int i=0; i <= OrdersTotal(); i++)

{

if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

if (OrderSymbol() == Symbol())

TotalOrders++;

}

if (TotalOrders<1)

{

ticket=OrderSend(Symbol(), OP_Buy, 0.1, Ask, 3, 0, 0, NULL,LimeGreen);

stop=(Ask+stopsize*Point);

prof=(Ask-profsize*Point);

OrderModify( ticket, OrderOpenPrice(), stop, prof, 0, Blue);

}

err=GetLastError();

// Comment("This is a test ", err, " ", stop, " ", prof);

Comment(" ");

return(0);

}

hock87

That code will not compile (replace OP_Buy with OP_BUY) and I do not see at all any conditions for an opening of another order. Per moment you are allowing only one order (the "if (TotalOrders<1)" line) That should be your starting point

 

CCI fdoe hpp

I downloaded this indicator from one of the threads and it is far better than the CCI-zones or Ma-zones indicators.

Can it be adapted to show on the screen as in a zone indicator?

It is set to CCI setting 13 but if it can be made into a variable setting indicator easily then that would be a bonus - but very much a secondary request.

It is a Forex-TSD indicator but no mq4 folder was with it.

Thanks

TEAMTRADER

Files:
cci_fdoehpp.ex4  19 kb
Reason: