Coding help - page 65

 

Here is a function that will check for order open times and return the price of the one with the most recent open time (if there were no previous orders, it will return 0)

double lastOrderOpenPrice(int magicNumber=0)

{

datetime lastTime = 0;

double lastPrice = 0;

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

{

if (OrderSelect(i,SELECT_BY_POS, MODE_TRADES)==false) break;

if (magicNumber!=0)

if (OrderMagicNumber() != magicNumber) continue;

if (OrderSymbol() != Symbol()) continue;

if (OrderOpenTime() <= lastTime) continue;

lastTime = OrderOpenTime();

lastPrice = OrderOpenPrice();

}

if (lastTime==0)

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

{

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

if (magicNumber!=0)

if (OrderMagicNumber() != magicNumber) continue;

if (OrderSymbol() != Symbol()) continue;

if (OrderOpenTime() <= lastTime) continue;

lastTime = OrderOpenTime();

lastPrice = OrderOpenPrice();

}

return(lastPrice);

}

[/PHP]

The assumtion is that currently open orders have times more recent than the already closed orders. If you wish to avoid that assumption, comment out this line :

[PHP] if (lastTime==0)

dasio:
Hi,

i need a double function that result me the orderopenprice() of the last openorder.

Someone can help me?

Thank you
 

Hi,

i use this code for calculate lotsieze. Sometimes i receive the 131 error. The code is ok?

double Lotti1(double StopLoss,double Rischio_per_trade){

double MyLots,AllowedLots,MaxLots,MinLot,StopValue,TickValue;

int RightLots;

AllowedLots=(AccountFreeMargin()* Rischio_per_trade/100);

if (Digits==2 || Digits==4)

TickValue=MarketInfo(Symbol(),MODE_TICKVALUE)/10;

else

TickValue=MarketInfo(Symbol(),MODE_TICKVALUE);

StopValue=StopLoss*TickValue;

MinLot=MarketInfo(Symbol(),MODE_MINLOT);

MaxLots=MarketInfo(Symbol(),MODE_MAXLOT);

RightLots=MathRound(AllowedLots/StopValue);

double soldi_ora = AccountBalance()/100;

MyLots = soldi_ora*(Rischio_per_trade/10);

MyLots = NormalizeDouble(MyLots/StopLoss,2);

MyLots = NormalizeDouble(MyLots/(MarketInfo(Symbol(),MODE_TICKVALUE)/100),2);

MyLots = NormalizeDouble(MyLots/100,2);

return(MyLots);

}[/PHP]

the Stoploss is = [PHP]StopLoss= NormalizeDouble(Ask-SLbuy()-20*Point,5)*10000;

and Rischio_per_trade = 0.5.

Thank you

 

dasio

try the function from this post : https://www.mql5.com/en/forum/general

dasio:
Hi,

i use this code for calculate lotsieze. Sometimes i receive the 131 error. The code is ok?

double Lotti1(double StopLoss,double Rischio_per_trade){

double MyLots,AllowedLots,MaxLots,MinLot,StopValue,TickValue;

int RightLots;

AllowedLots=(AccountFreeMargin()* Rischio_per_trade/100);

if (Digits==2 || Digits==4)

TickValue=MarketInfo(Symbol(),MODE_TICKVALUE)/10;

else

TickValue=MarketInfo(Symbol(),MODE_TICKVALUE);

StopValue=StopLoss*TickValue;

MinLot=MarketInfo(Symbol(),MODE_MINLOT);

MaxLots=MarketInfo(Symbol(),MODE_MAXLOT);

RightLots=MathRound(AllowedLots/StopValue);

double soldi_ora = AccountBalance()/100;

MyLots = soldi_ora*(Rischio_per_trade/10);

MyLots = NormalizeDouble(MyLots/StopLoss,2);

MyLots = NormalizeDouble(MyLots/(MarketInfo(Symbol(),MODE_TICKVALUE)/100),2);

MyLots = NormalizeDouble(MyLots/100,2);

return(MyLots);

}[/PHP]

the Stoploss is = [PHP]StopLoss= NormalizeDouble(Ask-SLbuy()-20*Point,5)*10000;

and Rischio_per_trade = 0.5.

Thank you
 

Dear friends,

Respectfully wish you and all forum members health and happiness in coming New Year ! I really feel thanksful to many outstanding and generous coders here as well as brilliant ideas from this forum's members. All help me a lot in improving my trading skills (though i'm still an idiot in this career )

Recently, in review of the market and my trading approach, I think about an indicator that would help me much (and others as well, maybe). My idea is just simple, but transfer it into code is beyond of my ability. Don't know such indicator exist or not, so I will describe my idea in detail and do hope someone would help me find or make the one best fit.

- General idea : I want to track the market price continuously within given fixed range of points. The indicator would give me some necessary information about price action within segments of price (given fixed range) such as: (1) upper level, (2) lower level, (3) median level, (4) number of bars within the range. I also like to know Point of Control (POC) level of bars in the given range but maybe it's too complicated in coding and consume much PC's memory.

- Analogy : I found popular indicators as "Market Profile", "Price Channel", or "Session HiLo", ... share much my idea. But all of them are limited by time interval as Hourly, Daily, ... not based on given fixed range or lack some features as I mentioned above. I have tried recoding on them to adapt my idea but not successful till now.

- Wishlist about indicator : (1) Input parameter: Fixed Range of points; Time Interval (in minutes, hours, or days) or Bar Number used to count Number of Bars closed within the Range given; Alert when price touch levels (optional)

(2) Output on main chart : display horizontal line corresponding to levels of range (upper, lower, middle), and text inform number of bars counted within the range for given time.

(3) Update continuously : the information would be update in 3 cases : (a) price makes new High of current given range, (b) new Low of current given range, (c) more and more bars consolidate within current given range.

I usually have to do all these things manually. Now I hope the indicator would help to simplify my work, save time, and keep my focus on price action. Searching over internet but I can't find such tool. If you know one, or make one, I would be very much grateful.

Thank you for your consideration and your help !

And again, Happy New Year to you !

Best Regards,

fareastol

oh i forgot attached picture about what i image of the indicator

Files:
 

I attach another picture to clarify my idea :

a) High or Low of the current range is determined in separate with the input Bar Number. High/Low is adaptive to given range size and current market price action.

b) The input Bar Number is just used to calculate the number of bars closed within current range.

c) I can put the indicator more than once on one chart, with different input setting, of course.

fareastol:
Dear friends,

Respectfully wish you and all forum members health and happiness in coming New Year ! I really feel thanksful to many outstanding and generous coders here as well as brilliant ideas from this forum's members. All help me a lot in improving my trading skills (though i'm still an idiot in this career )

Recently, in review of the market and my trading approach, I think about an indicator that would help me much (and others as well, maybe). My idea is just simple, but transfer it into code is beyond of my ability. Don't know such indicator exist or not, so I will describe my idea in detail and do hope someone would help me find or make the one best fit.

- General idea : I want to track the market price continuously within given fixed range of points. The indicator would give me some necessary information about price action within segments of price (given fixed range) such as: (1) upper level, (2) lower level, (3) median level, (4) number of bars within the range. I also like to know Point of Control (POC) level of bars in the given range but maybe it's too complicated in coding and consume much PC's memory.

- Analogy : I found popular indicators as "Market Profile", "Price Channel", or "Session HiLo", ... share much my idea. But all of them are limited by time interval as Hourly, Daily, ... not based on given fixed range or lack some features as I mentioned above. I have tried recoding on them to adapt my idea but not successful till now.

- Wishlist about indicator : (1) Input parameter: Fixed Range of points; Time Interval (in minutes, hours, or days) or Bar Number used to count Number of Bars closed within the Range given; Alert when price touch levels (optional)

(2) Output on main chart : display horizontal line corresponding to levels of range (upper, lower, middle), and text inform number of bars counted within the range for given time.

(3) Update continuously : the information would be update in 3 cases : (a) price makes new High of current given range, (b) new Low of current given range, (c) more and more bars consolidate within current given range.

I usually have to do all these things manually. Now I hope the indicator would help to simplify my work, save time, and keep my focus on price action. Searching over internet but I can't find such tool. If you know one, or make one, I would be very much grateful.

Thank you for your consideration and your help !

And again, Happy New Year to you !

Best Regards,

fareastol

oh i forgot attached picture about what i image of the indicator
Files:
 

I think I have made something myself after all. Now sharing with you.

As stated inside of indicator, I do not invent anything, just mix two related indicators I have. Maybe it's not well "mixed"

Please take a look and make it better if you think it's useful !

 

Draw multiple rectangle object

Hi,

i'm trying to draw multiple rectangle checking the last n candle.

The point have a simple rule.

Attached there is an example.

The big rectangle without background define the rule ( check price included from point 1 to poin 2 using moving everage).

The point for draw the rectangle is the high and low of the bar with high highest of the range.

How i can code it?

Thank you for your reply.

sorry,

i can't attach an image now. However let assume to have two Moving Average .Point 1 is the cross of the fast MA with slow MA upward and point 2 is the cross of fast MA with slow MA downward.

 

Could anybody help me to modify the attached rsi chart bars indicator ???

This indicator displays blue bars when RSi is above 50 level and red bars below this level.

Actually the 50 level is the middle level of the RSI. It woul be much usefull if two more levels would be added at 70 and at 30 wich are the real overbought and oversold levels. and when the RSI passes these two levels 70/30, the candles should change colours too. I would really appreciate any help, and thanks in addvance.

Files:
 

Laszlo,

Try this version out. It still works with 2 levels but it shows (or rather, does not show) 3 states. It colors the bars when levels are broken up or down and if the rsi value is in between the 2 levels it leaves the bars as is (so they are simple, non-colored by the indicator, bars) Here is an example how it looks like and how it compares to "regular" rsi :

Laszlo:
Could anybody help me to modify the attached rsi chart bars indicator ???

This indicator displays blue bars when RSi is above 50 level and red bars below this level.

Actually the 50 level is the middle level of the RSI. It woul be much usefull if two more levels would be added at 70 and at 30 wich are the real overbought and oversold levels. and when the RSI passes these two levels 70/30, the candles should change colours too. I would really appreciate any help, and thanks in addvance.
 
fareastol:
I think I have made something myself after all. Now sharing with you.

As stated inside of indicator, I do not invent anything, just mix two related indicators I have. Maybe it's not well "mixed"

Please take a look and make it better if you think it's useful !

Fareastol, I like your range indicator and what I am thinking that will be cool if you can add "start point" drag (which you have) and "end point drag" and then it will automatically draw range for that period.

Reason: