ICustom function - page 10

 

Hi, could you help me with the elaboration of this expert.

Based on FreedomBar indicator...

If previous square closes red -> sell (market price) -> close trade in the next previous square change to blue and reverse to buy (market price)

Idem on buy orders

TF, tp, sl and trailing stop options would be nice.

Thanks in advance

Files:
 

Any help please. I am reading from and indicator into an EA using icustom, during backtest the trend runs quite happily, then for some reason the icustom parameters reverse so my trend is going up instead of down even though the indicator is showing down after the trade is activated i corrects itself then happens again some time later

 
increase:
Any help please. I am reading from and indicator into an EA using icustom, during backtest the trend runs quite happily, then for some reason the icustom parameters reverse so my trend is going up instead of down even though the indicator is showing down after the trade is activated i corrects itself then happens again some time later

mmm so the indicator seems to be the problem it is SuperTrend volty like but I have had the problem with other non repainting indicators such as FX Sniper Ergodic and Fisher.

The challenge seems to be that there are many times when the indicator points in a direction say down, but the start point of the move ends up being lower than the finish causing the indicator to show down but the data reads up.

Any comment s on this, does anyone have a non repainting indicator that does not do this, or any other solution?

Please see attached pic

Files:
pic.jpg  38 kb
 

iCustom function

hi all... this is my first post

i need some help with the ea im trying to create. this ea will be used to close position based on the color of the indicator but i'll open the position manually. since i don't have the decompile version the indicator, i think icustom is the way to go.

but how do i call the function based on the color?

eg. if i used Heikin Ashi_SW and i want to close sell position when the color is blue after the bar is closed and vice versa.

thanx in advance

 

ICustom problems

I have a simple Custom Indicator with no externs called #TestIndicator that fills 8 buffers with the number 1.0 but when I bring back the buffers in my EA the buffer results are always 0 . Can you help me with this.

#TestIndicator

#property indicator_chart_window

#property indicator_buffers 8

double buf4_up[];

double buf4_down[];

double buf3_up[];

double buf3_down[];

double buf2_up[];

double buf2_down[];

double buf1_up[];

double buf1_down[];

int UniqueNum = 0070;

string shortname = "";

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

//| Custom indicator initialization function |

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

int init()

{

shortname = "#TFX";

IndicatorBuffers(8);

IndicatorShortName(shortname);

//---- indicators

SetIndexBuffer(0,buf4_up);

SetIndexBuffer(1,buf4_down);

SetIndexBuffer(2,buf3_up);

SetIndexBuffer(3,buf3_down);

SetIndexBuffer(4,buf2_up);

SetIndexBuffer(5,buf2_down);

SetIndexBuffer(6,buf1_up);

SetIndexBuffer(7,buf1_down);

//----

return(0);

}

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

//| Custom indicator deinitialization function |

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

int deinit()

{

//----

//----

return(0);

}

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

//| Custom indicator iteration function |

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

int start()

{

int limit;

int counted_bars = IndicatorCounted();

//---- the last calculated bar will be recalculated

if(counted_bars > 0)

counted_bars--;

limit = Bars - counted_bars - 1;

//---- the main cycle

for(int i = limit; i >= 0; i--)

{

//----

buf4_up=1.0;

buf4_down=1.0;

buf3_up=1.0;

buf3_down=1.0;

buf2_up=1.0;

buf2_down=1.0;

buf1_up=1.0;

buf1_down=1.0;

}

//----

//----

//----

return(0);

}

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

[/CODE]

EA Code

[CODE]

double test4_up[];

double test4_down[];

double test3_up[];

double test3_down[];

double test2_up[];

double test2_down[];

double test1_up[];

double test1_down[];

int UniqueNum = 009;

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

//| expert initialization function |

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

int init()

{

//----

Print("Inside init");

//----

return(0);

}

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

//| expert deinitialization function |

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

int deinit()

{

//----

Print("Inside deinit");

//----

return(0);

}

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

//| expert start function |

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

int start()

{

//----

Print("Inside start");

int counted_bars=IndicatorCounted();

int y5m=0, y1h=0, y30m=0, y15m=0, yy=0;

int i=0;

int limit=Bars-counted_bars;

for(i=0;i<limit;i++)

{

test4_up = iCustom(NULL, 0, "#TestIndicator",0,i);

test4_down = iCustom(NULL, 0, "#TestIndicator",1,i);

}

for(i=0;i<30;i++)

{

Print("Test 4 UP ", test4_up," Bar ",i );

Print("Test 4 DOWN ", test4_down," Bar ",i );

//Print("This is a test");

}

//----

return(0);

}

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

Results in Tester

 
Xaun:
I have a simple Custom Indicator with no externs called #TestIndicator that fills 8 buffers with the number 1.0 but when I bring back the buffers in my EA the buffer results are always 0 . Can you help me with this.

EA Code

double test4_up[];

double test4_down[];

double test3_up[];

double test3_down[];

double test2_up[];

double test2_down[];

double test1_up[];

double test1_down[];

int UniqueNum = 009;

..

..

...

......

..

int i=0;

int limit=Bars-counted_bars;

ArrayResize(test4_up, limit);

ArrayResize(test4_down, limit);

for(i=0;i<limit;i++)

{

test4_up = iCustom(NULL, 0, "#TestIndicator",0,i);

test4_down = iCustom(NULL, 0, "#TestIndicator",1,i);

}

for(i=0;i<30;i++)

{

Print("Test 4 UP ", test4_up," Bar ",i );

Print("Test 4 DOWN ", test4_down," Bar ",i );

//Print("This is a test");

}

//----

return(0);

}

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

]

Maybay you need define size of array in you EA.

 

Thanks

okfar:
Maybay you need define size of array in you EA.

Thanks Okfar. That was exactly the problem

 

Depending how your going to access your data you donot have to refill the array on each tick just like you dont have to recalculate indicators. see

bool ArraySetAsSeries(double&array[], bool set)Sets indexing direction of the array. If the set parameter has the TRUE value, the array will be indexed in a reversed order, i.e., the last element has a zero index. The FALSE value sets a standard indexing order. The function returns the previous status.

 

...

You are trying to use features that are meant to be used exclusively from an indicator.

IndicatorCounted() has no meaning at all when called from an EA. It always returns -1 when called within EA code. Try using a constant instead (like in your second loop) or Bars (if you want the whole history).

Also, arrays used within EA should be sized, initialized and the whole work that normally metatrader does when it comes to indicators and buffers within indicators. EA does not have an equivalent of SetIndexBuffer() that is used in indicators. You are having uninitialized arrays in your Ea and only metatrader prevented your EA from crashing the platform (it always returns 0 in those cases, since the element value you are trying to read does not exist, and in fact, those arrays do not exist (they are just declared, not allocated, initialized,...))

regards

mladen

Xaun:
I have a simple Custom Indicator with no externs called #TestIndicator that fills 8 buffers with the number 1.0 but when I bring back the buffers in my EA the buffer results are always 0 . Can you help me with this.

#TestIndicator

#property indicator_chart_window

#property indicator_buffers 8

double buf4_up[];

double buf4_down[];

double buf3_up[];

double buf3_down[];

double buf2_up[];

double buf2_down[];

double buf1_up[];

double buf1_down[];

int UniqueNum = 0070;

string shortname = "";

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

//| Custom indicator initialization function |

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

int init()

{

shortname = "#TFX";

IndicatorBuffers(8);

IndicatorShortName(shortname);

//---- indicators

SetIndexBuffer(0,buf4_up);

SetIndexBuffer(1,buf4_down);

SetIndexBuffer(2,buf3_up);

SetIndexBuffer(3,buf3_down);

SetIndexBuffer(4,buf2_up);

SetIndexBuffer(5,buf2_down);

SetIndexBuffer(6,buf1_up);

SetIndexBuffer(7,buf1_down);

//----

return(0);

}

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

//| Custom indicator deinitialization function |

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

int deinit()

{

//----

//----

return(0);

}

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

//| Custom indicator iteration function |

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

int start()

{

int limit;

int counted_bars = IndicatorCounted();

//---- the last calculated bar will be recalculated

if(counted_bars > 0)

counted_bars--;

limit = Bars - counted_bars - 1;

//---- the main cycle

for(int i = limit; i >= 0; i--)

{

//----

buf4_up=1.0;

buf4_down=1.0;

buf3_up=1.0;

buf3_down=1.0;

buf2_up=1.0;

buf2_down=1.0;

buf1_up=1.0;

buf1_down=1.0;

}

//----

//----

//----

return(0);

}

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

[/code]EA Code

[code]

double test4_up[];

double test4_down[];

double test3_up[];

double test3_down[];

double test2_up[];

double test2_down[];

double test1_up[];

double test1_down[];

int UniqueNum = 009;

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

//| expert initialization function |

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

int init()

{

//----

Print("Inside init");

//----

return(0);

}

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

//| expert deinitialization function |

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

int deinit()

{

//----

Print("Inside deinit");

//----

return(0);

}

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

//| expert start function |

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

int start()

{

//----

Print("Inside start");

int counted_bars=IndicatorCounted();

int y5m=0, y1h=0, y30m=0, y15m=0, yy=0;

int i=0;

int limit=Bars-counted_bars;

for(i=0;i<limit;i++)

{

test4_up = iCustom(NULL, 0, "#TestIndicator",0,i);

test4_down = iCustom(NULL, 0, "#TestIndicator",1,i);

}

for(i=0;i<30;i++)

{

Print("Test 4 UP ", test4_up," Bar ",i );

Print("Test 4 DOWN ", test4_down," Bar ",i );

//Print("This is a test");

}

//----

return(0);

}

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

Results in Tester...

 

Coding Question

I have an indicator that I am very fond of and have demo'd it for a couple of weeks and been pretty successful. Is there a way where I can automate buy/sell orders based on the indicator? Short summary is it's a small arrow pointing either up or down on the chart when the indicators I like line up. Is there a way that when the arrow pops up it will place an order for me?

Reason: