MQL4 Learning - page 133

 
[/TD]

[/TR]

[/TABLE]

New Strategy Builder 3.2 Beta version for MT4

[TABLE="class: contentpaneopen, width: 976"]

[TR]

[TD="colspan: 2"]We are proud to announce a new beta release for the Strategy Builder 3.2 (the best tool to create Expert Advisors). This new beta version includes The EA Signal Builder icon, the MQL+ icon, and support for MT4 Build 600. See the EA Signal Builder icon in action in the video below - It is the easiest way to build EAs.

Molanis Strategy Builder for MetaTrader

NoProgra EA Builder is a powerful graphic tool to create Expert Advisors and Custom Indicators

NoProgra Builder is the only expert advisor builder based on natural language - NoProgra Expert Advisor Builder for MetaTrader

StrategyQuant v.3.6 Use StrategyQuant to build new automated trading systems for any market or timeframe

StrategyQuant

 

Hi

if I have the two times

datetime starttime = iTime(Symbol(),PERIOD_D1,0)+ 3600*startHour + 60*startMinute;

datetime endtime = iTime(Symbol(),PERIOD_D1,0)+ 3600*endtHour + 60*endMinute;

How can I write the functions that gives me "true" back, when the actual time is between starttime and endtime

and give "false" back, if it is later or earlier?

 
sunshineh:
Hi

if I have the two times

datetime starttime = iTime(Symbol(),PERIOD_D1,0)+ 3600*startHour + 60*startMinute;

datetime endtime = iTime(Symbol(),PERIOD_D1,0)+ 3600*endtHour + 60*endMinute;

How can I write the functions that gives me "true" back, when the actual time is between starttime and endtime

and give "false" back, if it is later or earlier?

sunshineh

Check this post : https://www.mql5.com/en/forum/184052

 

Hi Again,

I got stuck in figuring this out. Could somebody enlighten me the correct way.

I have this indicator which i would like to use it multiple time on the same chart, thus giving it special prefix is probably the best way to differentiate from each other.

For example :-

string Prefix="Indi_1"; ObjectCreate(Prefix+"Box", OBJ_RECTANGLE, 0, time1, price1, time2, price2);

I can just change the prefix "Indi_1", "Indi_2", "Indi_3" and so on if i want to attach it to the same chart. However, it gets troublesome when it goes over 10 instances and beyond.

My question is, is there any workaround to use the same indicator without changing it's prefix manually ? Like giving it auto id to the indicator ?

 
cawat:
Hi Again,

I got stuck in figuring this out. Could somebody enlighten me the correct way.

I have this indicator which i would like to use it multiple time on the same chart, thus giving it special prefix is probably the best way to differentiate from each other.

For example :-

I can just change the prefix "Indi_1", "Indi_2", "Indi_3" and so on if i want to attach it to the same chart. However, it gets troublesome when it goes over 10 instances and beyond.

My question is, is there any workaround to use the same indicator without changing it's prefix manually ? Like giving it auto id to the indicator ?

You could do it from a loop (like for (int i=0; i < nnn; i++) ObjectCreate("Prefix_"+i+"Box", OBJ_RECTANGLE, 0, .....); ) but then you have to have times and prices stored in some array which would be accessible with the price1, price2 and so on ...

You have to decide which way would be easier to implement in your code

 

It is not so simple question as it seems to be.

I preferably use a dynamic prefix, that derives from rand() function. But sometimes indicators still get identical number from the rand(); my guess is the default seed for the rand() is taken from a clock counter, which lasts for 16 milliseconds.

So I use the GetTickCount (directly or as the seed for rand()), but I keep reading it in a loop until the value changes. Then I am sure no other indicator gets the same value, for a cost of decent delay.

Another way is to increment a stored prefix - place it somewhere (to global variables, or a file). The indicators work in sequence, so they do not interfere when saving the new prefix. This works until you delete the GV or file by accident.

 
mladen:
You could do it from a loop (like for (int i=0; i < nnn; i++) ObjectCreate("Prefix_"+i+"Box", OBJ_RECTANGLE, 0, .....); ) but then you have to have times and prices stored in some array which would be accessible with the price1, price2 and so on ... You have to decide which way would be easier to implement in your code

Thanks Mladen

Ovo:
It is not so simple question as it seems to be.

I preferably use a dynamic prefix, that derives from rand() function. But sometimes indicators still get identical number from the rand(); my guess is the default seed for the rand() is taken from a clock counter, which lasts for 16 milliseconds.

So I use the GetTickCount (directly or as the seed for rand()), but I keep reading it in a loop until the value changes. Then I am sure no other indicator gets the same value, for a cost of decent delay.

Another way is to increment a stored prefix - place it somewhere (to global variables, or a file). The indicators work in sequence, so they do not interfere when saving the new prefix. This works until you delete the GV or file by accident.

Thanks Ovo, i will try to research more on this

 
cawat:
My question is, is there any workaround to use the same indicator without changing it's prefix manually ? Like giving it auto id to the indicator ?

Hi, i'm still having the same problem for this indicator. At the moment i was only able to figure out how to make incremental counter for indicator/object's id and i can attach it multiple time on the same chart.

But problem arise if i restart the terminal, it will act as i'm attaching another indicator which i'm not.

How do i filter this out ? Any help is appreciated. Thanks

#property copyright "FX9"

#property link "FX9"

#property indicator_chart_window

extern double FiboLevel1=0.000;

extern double FiboLevel2=2.0;

extern double FiboLevel3=3.0;

extern double FiboLevel4=4.0;

extern double FiboLevel5=5.0;

extern double FiboLevel6=6.0;

extern double FiboLevel7=7.0;

extern double FiboLevel8=1.000;

extern string FiboPrefix="FX9-Fibo";

color levelColor = Lime;

string objName;

int testObj;

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

void init()

{

//---- indicators

testObj = ObjectsTotal(OBJ_FIBO);

// Set the name if chart is empty

if(testObj == 0){

objName = StringConcatenate(Symbol()+"-", FiboPrefix+"-"+(testObj+1));

}

testObj++;

if(UninitializeReason() != REASON_CHARTCHANGE){

objName = StringConcatenate(Symbol()+"-", FiboPrefix+"-"+testObj);

}

Comment("");

//----

//return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator deinitialization function |

//+------------------------------------------------------------------+

void deinit()

{

//----

Comment("");

//----

// return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator iteration function |

//+------------------------------------------------------------------+

void start()

{

//----

fibo();

//----

// return(0);

}

//+------------------------------------------------------------------+

// Create Fibo

void fibo() {

int fibHigh = iHighest(Symbol(),Period(),MODE_HIGH,54,36);

int fibLow = iLowest(Symbol(),Period(),MODE_LOW,72,36);

datetime highTime = Time[fibHigh];

datetime lowTime = Time[fibLow];

if(fibHigh>fibLow){

WindowRedraw();

drawFibo(highTime, High[fibHigh], lowTime, Low[fibLow]);

}

else{

WindowRedraw();

drawFibo(lowTime, Low[fibLow], highTime, High[fibHigh]);

}

}

// Draw Fibo

void drawFibo (datetime t1, double p1, datetime t2, double p2 ) {

ObjectCreate(objName,OBJ_FIBO,0,t1,p1,t2,p2);

double fiboPrice1=ObjectGet(objName,OBJPROP_PRICE1);

double fiboPrice2=ObjectGet(objName,OBJPROP_PRICE2);

double pipDist = MathAbs(fiboPrice1 - fiboPrice2);

pipDist = pipDist / Point / 10;

ObjectSet(objName,OBJPROP_LEVELCOLOR,levelColor);

ObjectSet(objName,OBJPROP_LEVELWIDTH,1);

ObjectSet(objName,OBJPROP_LEVELSTYLE,STYLE_SOLID);

ObjectSet(objName,OBJPROP_RAY,false);

ObjectSet(objName,OBJPROP_FIBOLEVELS,8);

ObjectSet(objName,OBJPROP_FIRSTLEVEL+0,FiboLevel1);

ObjectSet(objName,OBJPROP_FIRSTLEVEL+1,FiboLevel2);

ObjectSet(objName,OBJPROP_FIRSTLEVEL+2,FiboLevel3);

ObjectSet(objName,OBJPROP_FIRSTLEVEL+3,FiboLevel4);

ObjectSet(objName,OBJPROP_FIRSTLEVEL+4,FiboLevel5);

ObjectSet(objName,OBJPROP_FIRSTLEVEL+5,FiboLevel6);

ObjectSet(objName,OBJPROP_FIRSTLEVEL+6,FiboLevel7);

ObjectSet(objName,OBJPROP_FIRSTLEVEL+7,FiboLevel8);

ObjectSetFiboDescription(objName, 0,DoubleToStr(FiboLevel1*100,1));

ObjectSetFiboDescription(objName, 1," A - 200 ");

ObjectSetFiboDescription(objName, 2," B - 300 ");

ObjectSetFiboDescription(objName, 3," C - 400 ");

ObjectSetFiboDescription(objName, 4," D - 500 ");

ObjectSetFiboDescription(objName, 5," E - 600 ");

ObjectSetFiboDescription(objName, 6," F - 700 ");

ObjectSetFiboDescription(objName, 7,DoubleToStr(pipDist, 1)+" Pips ");

}

 
cawat:
Hi, i'm still having the same problem for this indicator. At the moment i was only able to figure out how to make incremental counter for indicator/object's id and i can attach it multiple time on the same chart.

But problem arise if i restart the terminal, it will act as i'm attaching another indicator which i'm not.

How do i filter this out ? Any help is appreciated. Thanks

#property copyright "FX9"

#property link "FX9"

#property indicator_chart_window

extern double FiboLevel1=0.000;

extern double FiboLevel2=2.0;

extern double FiboLevel3=3.0;

extern double FiboLevel4=4.0;

extern double FiboLevel5=5.0;

extern double FiboLevel6=6.0;

extern double FiboLevel7=7.0;

extern double FiboLevel8=1.000;

extern string FiboPrefix="FX9-Fibo";

color levelColor = Lime;

string objName;

int testObj;

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

void init()

{

//---- indicators

testObj = ObjectsTotal(OBJ_FIBO);

// Set the name if chart is empty

if(testObj == 0){

objName = StringConcatenate(Symbol()+"-", FiboPrefix+"-"+(testObj+1));

}

testObj++;

if(UninitializeReason() != REASON_CHARTCHANGE){

objName = StringConcatenate(Symbol()+"-", FiboPrefix+"-"+testObj);

}

Comment("");

//----

//return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator deinitialization function |

//+------------------------------------------------------------------+

void deinit()

{

//----

Comment("");

//----

// return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator iteration function |

//+------------------------------------------------------------------+

void start()

{

//----

fibo();

//----

// return(0);

}

//+------------------------------------------------------------------+

// Create Fibo

void fibo() {

int fibHigh = iHighest(Symbol(),Period(),MODE_HIGH,54,36);

int fibLow = iLowest(Symbol(),Period(),MODE_LOW,72,36);

datetime highTime = Time[fibHigh];

datetime lowTime = Time[fibLow];

if(fibHigh>fibLow){

WindowRedraw();

drawFibo(highTime, High[fibHigh], lowTime, Low[fibLow]);

}

else{

WindowRedraw();

drawFibo(lowTime, Low[fibLow], highTime, High[fibHigh]);

}

}

// Draw Fibo

void drawFibo (datetime t1, double p1, datetime t2, double p2 ) {

ObjectCreate(objName,OBJ_FIBO,0,t1,p1,t2,p2);

double fiboPrice1=ObjectGet(objName,OBJPROP_PRICE1);

double fiboPrice2=ObjectGet(objName,OBJPROP_PRICE2);

double pipDist = MathAbs(fiboPrice1 - fiboPrice2);

pipDist = pipDist / Point / 10;

ObjectSet(objName,OBJPROP_LEVELCOLOR,levelColor);

ObjectSet(objName,OBJPROP_LEVELWIDTH,1);

ObjectSet(objName,OBJPROP_LEVELSTYLE,STYLE_SOLID);

ObjectSet(objName,OBJPROP_RAY,false);

ObjectSet(objName,OBJPROP_FIBOLEVELS,8);

ObjectSet(objName,OBJPROP_FIRSTLEVEL+0,FiboLevel1);

ObjectSet(objName,OBJPROP_FIRSTLEVEL+1,FiboLevel2);

ObjectSet(objName,OBJPROP_FIRSTLEVEL+2,FiboLevel3);

ObjectSet(objName,OBJPROP_FIRSTLEVEL+3,FiboLevel4);

ObjectSet(objName,OBJPROP_FIRSTLEVEL+4,FiboLevel5);

ObjectSet(objName,OBJPROP_FIRSTLEVEL+5,FiboLevel6);

ObjectSet(objName,OBJPROP_FIRSTLEVEL+6,FiboLevel7);

ObjectSet(objName,OBJPROP_FIRSTLEVEL+7,FiboLevel8);

ObjectSetFiboDescription(objName, 0,DoubleToStr(FiboLevel1*100,1));

ObjectSetFiboDescription(objName, 1," A - 200 ");

ObjectSetFiboDescription(objName, 2," B - 300 ");

ObjectSetFiboDescription(objName, 3," C - 400 ");

ObjectSetFiboDescription(objName, 4," D - 500 ");

ObjectSetFiboDescription(objName, 5," E - 600 ");

ObjectSetFiboDescription(objName, 6," F - 700 ");

ObjectSetFiboDescription(objName, 7,DoubleToStr(pipDist, 1)+" Pips ");

}

If you want to use it in templates or you want to use multiple instances, the best way is that you enter the unique part of the name using parameters (that way even in templates, you can use those). Throw out the automatic counter and use FiboPrefixfor adding unique prefix and it will work perfectly in all the situations

 
mladen:
If you want to use it in templates or you want to use multiple instances, the best way is that you enter the unique part of the name using parameters (that way even in templates, you can use those). Throw out the automatic counter and use FiboPrefixfor adding unique prefix and it will work perfectly in all the situations

Yeah thats my thought after several week of finding the suitable way. Hurmm..

Anyway thanks for replying Mladen. Would buy you a coffee if you live nearby. Lol

Reason: