Coding help - page 100

 
dasssi:
mladen

first i hope you are not mad at me any more..

second i have an error tryind to load the Ea

dasssi

Try to rename the EA (due to French letter in the name it might be causing you a problem - no other problem can be the cause of that since it is a very simple EA)

 

thanks it works now/

does not look good on the strategy tester

 
dasssi:
thanks it works now/ does not look good on the strategy tester

It is just an example how an indicator should be called from an ea when it comes to signals. Far from being a complete EA (take a look at the new EAs in elite and advanced section and compare the code - you will see what do I mean). So, it was just a help to After-rage to solve his coding problem

 

Thank you !! It work well for enter positions. I don't know why my EA didn't work but doesn't matter. So i try to add code to close orders but it doesn't work too. Strange because i took like structure code for enter positions and i just double the volume of lot. Can you have a look ?

Files:
 
After-rage:
Thank you !! It work well for enter positions. I don't know why my EA didn't work but doesn't matter. So i try to add code to close orders but it doesn't work too. Strange because i took like structure code for enter positions and i just double the volume of lot. Can you have a look ?

After-rage

One way you can do that (close an opened order when the signal changes) is in the code now

Files:
 

Thank you so much ! It works very well. I will work on this and see why i was wrong.

 

Does someone know if is possible to change an indicator setting on execution time via code? for example i would like to have a CCI where the period is equal to the ATR so when the ATR change the CCI period change as well..like init the indicator at every new bar.. the proble is that i dont know how to re-init the indi via code.. i have tried to call the init() when the new bar is open and the period change correctly but the indicator wont refresh...last bar value is correct but i want the whole indi to repaint to the new settings.. i hope i was clear..Thanks

 
AtApi:
Does someone know if is possible to change an indicator setting on execution time via code? for example i would like to have a CCI where the period is equal to the ATR so when the ATR change the CCI period change as well..like init the indicator at every new bar.. the proble is that i dont know how to re-init the indi via code.. i have tried to call the init() when the new bar is open and the period change correctly but the indicator wont refresh...last bar value is correct but i want the whole indi to repaint to the new settings.. i hope i was clear..Thanks

If you want to repaint the whole indi values, simply set the main loop count in the start to Bars-1 and calculate the values with new settings

 

Thanx mladen for your quick answer...

please have a look at this example:

extern int IndicatorPeriod = 10;

extern int AtrPeriod= 10;

extern bool DynamicPeriod = TRUE;

int init()

{

if (DynamicPeriod)

{

double atr = NormalizeDouble(100*iATR(0,0,AtrPeriod,0),0);

IndicatorPeriod = atr;

}

}

int start()

{

datetime lastBarOpenTime;

datetime thisBarOpenTime = Time[0];

if (DynamicPeriod)

{

if(thisBarOpenTime != lastBarOpenTime)

{

lastBarOpenTime = thisBarOpenTime;

init();

}

}

int i,counted_bars=IndicatorCounted();

if(counted_bars<0) return(-1);

if(counted_bars>0) counted_bars--;

// is this what you are talking about?

int limit=MathMin(Bars-counted_bars,Bars-1);

for(i=limit; i>=0; i--) //MAIN LOOP

{

wherever calculation

}

}

 
AtApi:
Thanx mladen for your quick answer...

please have a look at this example:

extern int IndicatorPeriod = 10;

extern int AtrPeriod= 10;

extern bool DynamicPeriod = TRUE;

int init()

{

if (DynamicPeriod)

{

double atr = NormalizeDouble(100*iATR(0,0,AtrPeriod,0),0);

IndicatorPeriod = atr;

}

}

int start()

{

datetime lastBarOpenTime;

datetime thisBarOpenTime = Time[0];

if (DynamicPeriod)

{

if(thisBarOpenTime != lastBarOpenTime)

{

lastBarOpenTime = thisBarOpenTime;

init();

}

}

int i,counted_bars=IndicatorCounted();

if(counted_bars<0) return(-1);

if(counted_bars>0) counted_bars--;

// is this what you are talking about?

int limit=MathMin(Bars-counted_bars,Bars-1);

for(i=limit; i>=0; i--) //MAIN LOOP

{

wherever calculation

}

}

AtApi

If you want to save values to the buffer (one value per exact time for that bar) then yes, that is the correct way. But if you want all the bars to be "repainted", then set the linit to be always equal toBars-1

Reason: