You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
(In the beginning, I thought it would be easy)
cori
cori
i've been sitting on my hands on this one... i thought it may be tougher than u expected! éet me know if i can help u debug!
regards,
hugues
I have done it mostly, although I cannot say if the results are the same as the original will give. This is because I don't understand what this indicator should give and I don't have a tradestation.
One main Problem was the ability of Easy Language to call a function on a specified bar using a syntax like x = myFunction( param1, param2)[5] which will call the function five bars back. The function then will get this bar as its actual one.
My problem is, that my indicator gets always more then 10 upFracs and therefore the calculated value is -1.
I have looked at this problem the whole evening yesterday and cannot find it.
I post you here what I have done so far. Maybe you can see it. I think, either I have taken one calculation wrong or I have a wrong condition in an if statement.
It's too bad, that there are no Debugger for the programs, this would make it easy to find such errors.
My codestyle is a bit different from yours, but I hope, you can understand it.
If you find something, give me a hint.
with regards, cori
/* ****************************************************************** */ /* ABillW_ActiveFractal */ /* ------------------------------------------------------------------ */ /* I dont understand what is calculated here. All I have is a */ /* badly documented programming example */ /* */ /* Copyright and pricing */ /* */ /* This code was developed by coriFX 2005. */ /* */ /* You can use this code to make money as much as you wish without */ /* fee. If you have made your first million using my code, I would */ /* ask you to send me 10%. contact me at { corifx at o2go dot de }. */ /* I will send you the information for money transfer. */ /* */ /* ****************************************************************** */ #property copyright "developed by coriFX 2005" //---- indicator settings #property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 Blue #property indicator_color2 Red // Indicator buffer double bufUpFrac[]; double bufDownFrac[]; /* ------------------------------------------------------------------ */ /* Definitionen of Standardvalues */ /* ------------------------------------------------------------------ */ #define NAME "ABillW_ActiveFractal" #define VERSION "0.1" /* ------------------------------------------------------------------ */ /* Includes */ /* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */ /* Imported functions and used libraries */ /* ------------------------------------------------------------------ */ #import /* ------------------------------------------------------------------ */ /* Parameters */ /* ------------------------------------------------------------------ */ extern bool debug = true; /* ------------------------------------------------------------------ */ /* Initialize */ /* ------------------------------------------------------------------ */ int init() { logOutput( ": initialize" ); if ( debug ) { logOutput( "-----> Debug enabled" ); } // initialize indicator IndicatorShortName( NAME ); SetIndexStyle( 0, DRAW_LINE ); SetIndexLabel( 0, "upFrac" ); if ( ! SetIndexBuffer( 0, bufUpFrac ) ) { logOutput( "cannot set Index Buffer 0" ); } SetIndexStyle( 1, DRAW_LINE ); SetIndexDrawBegin( 1, 20 ); SetIndexLabel( 1, "downFrac" ); if ( ! SetIndexBuffer( 1, bufDownFrac ) ) { logOutput( "cannot set Index Buffer 1" ); } return( 0 ); } /* ------------------------------------------------------------------ */ /* End. Free all resources */ /* ------------------------------------------------------------------ */ int deinit() { logOutput( ": deinitialize" ); return( 0 ); } /* ------------------------------------------------------------------ */ /* Main routine. Called at every tick */ /* ------------------------------------------------------------------ */ int start() { int counted = IndicatorCounted(); int remain = Bars - counted; int i; logOutput( StringConcatenate( ": start new cycle - counted: ", counted, ", remain: ", remain ) ); if ( counted < 0 ) { return( -1 ); } for ( i = 0; i < remain; i++ ) { calculateIndicatorValues( i ); } if ( debug ) { for ( i = 0; i < remain; i++ ) { logOutput( StringConcatenate( ": Buffers - bufUpFrac[", i, "] = ", bufUpFrac[i], ", bufDownFrac[", i, "] = ", bufDownFrac[i] ) ); } } } // Function to calculate the indicator values void calculateIndicatorValues( int shift ) { double upFrac = 0; double dnFrac = 0; bool stp_now = false; int i1 = 1; int maxFracsBack = 10; double value1 = High[Highest( Symbol(), 0, MODE_HIGH, 3, shift )]; double value2 = Low[Lowest( Symbol(), 0, MODE_LOW, 3, shift )]; double value3 = 0; double value4 = 0; double blBlue = calculateAverageHelper( High, Low, 13, 8 + shift ); // {blue} double blRed = calculateAverageHelper( High, Low, 8, 5 + shift ); // {red} double blGreen = calculateAverageHelper( High, Low, 5, 3 + shift ); // {green} if ( debug ) { logOutput( StringConcatenate( " - calculateIndicatorValues() - shift: ", shift, ", value1: ", value1, ", value2: ", value2, ", blBlue: ", blBlue, ", blRed: ", blRed, ", blGreen: ", blGreen ) ); } // Wenn dnFrac ueber blred liegt, dann ist es ungueltig // das vorhergehende frac wird dann getestet usw. stp_now = false; i1 = 1; value3 = calculateSwingLow( i1, Low, 2, 80, shift ); while ( i1 < maxFracsBack && value3 != -1 && ! stp_now ) { if ( value3 > blRed || value3 > value2 ) { i1 += 1; value3 = calculateSwingLow( i1, Low, 2, 80, shift ); } else { stp_now = TRUE; } } if ( stp_now ) { dnFrac = value3; } else { dnFrac = -1; } if ( i1 >= maxFracsBack ) { logOutput( StringConcatenate( ": ", i1 ," mehr als ", maxFracsBack, " dnFracs" ) ); } // Wenn upFrac unter blRed liegt, ist es ungueltig. // Das vorhergehende upFrac wird dann auf Gueltigkeit getestet usw. stp_now = false; i1 = 1; value4 = calculateSwingHigh( i1, High, 2, 80, shift ); while ( i1 < maxFracsBack && value4 != -1 && ! stp_now ) { if ( value4 < blRed || value4 < value1 ) { i1 += 1; value4 = calculateSwingHigh( i1, High, 2, 80, shift ); } else { stp_now = TRUE; } // I think this statement is not necessary // if date=930219 then print(d," ooh ",i1,stp_now,value4); } if ( stp_now ) { upFrac = value4; } else { upFrac = -1; } if ( i1 >= maxFracsBack ) { logOutput( StringConcatenate( ": ", i1 ," mehr als ", maxFracsBack, " upFracs" ) ); } logOutput( StringConcatenate( ": upFrac: ", upFrac, ", downFrac: ", dnFrac ) ); if ( upFrac != 0 && upFrac != -1 ) { bufUpFrac[shift] = upFrac; } else { bufUpFrac[shift] = bufUpFrac[shift - 1]; } if ( dnFrac != 0 && dnFrac != -1 ) { bufDownFrac[shift] = dnFrac; } else { bufDownFrac[shift] = bufDownFrac[shift - 1]; } return; } /* ------------------------------------------------------------------ */ /* Internal routines */ /* ------------------------------------------------------------------ */ // function SwingHigh as provided from Alexantry // double calculateSwingHigh( int occur, double price[], int strength, int length, int shift ) { /******************************************************************* Description: Swing High Provided By: Omega Research, Inc. (c) Copyright 1999 ********************************************************************/ int x = 0; int j = strength; int counter = 0; double price1 = 0; bool found = false; bool truth = false; if ( debug ) { logOutput( StringConcatenate( " - calculateSwingHigh() inputs - occur: ", occur, ", price[", shift, "]: ", price[shift], ", strength: ", strength, ", length: ", length, ", shift: ", shift ) ); } if ( j > 0 ) { counter = 0; while ( j < length && ! found ) { price1 = price[j + shift]; x = j + 1; truth = true; while ( truth && ( x - j ) <= strength ) { if ( price1 < price[x + shift] ) { truth = false; } x += 1; } x = j - 1; while ( truth && ( j - x ) <= strength ) { if ( price1 <= price[x + shift] ) { truth = false; } x -= 1; } if ( truth ) { counter += 1; } if ( counter >= occur ) { found = true; } j += 1; } } if ( ! found ) { price1 = -1; } if ( debug ) { logOutput( StringConcatenate( " - calculateSwingHigh() return: ", price1 ) ); } return( price1 ); } // function SwingLow as provided from Alexantry // double calculateSwingLow( int occur, double price[], int strength, int length, int shift ) { /******************************************************************* Description: Swing Low Provided By: Omega Research, Inc. (c) Copyright 1999 ********************************************************************/ int x = 0; int j = strength; int counter = 0; double price1 = 0; bool found = false; bool truth = false; if ( debug ) { logOutput( StringConcatenate( " - calculateSwingLow() inputs - occur: ", occur, ", price[", shift, "]: ", price[shift], ", strength: ", strength, ", length: ", length, ", shift: ", shift ) ); } if ( j > 0 ) { counter = 0; while ( j < length && ! found ) { price1 = price[j + shift]; x = j + 1; truth = true; while ( truth && ( x - j ) <= strength ) { if ( price1 > price[x + shift] ) { truth = false; } x += 1; } x = j - 1; while ( truth && ( j - x ) <= strength ) { if ( price1 >= price[x + shift] ) { truth = false; } x -= 1; } if ( truth ) { counter += 1; } if ( counter >= occur ) { found = true; } j += 1; } } if ( ! found ) { price1 = -1; } if ( debug ) { logOutput( StringConcatenate( " - calculateSwingLow() return: ", price1 ) ); } return( price1 ); } // function Average as provided from Alexantry // double calculateAverage( double price[], int length ) { /******************************************************************* Description: Simple Moving Average Provided By: Omega Research, Inc. (c) Copyright 1999 ********************************************************************/ if ( debug ) { logOutput( StringConcatenate( " - calculateAverage() inputs - price[0]: ", price[0], ", length: ", length ) ); } double sum = 0; int counter = 0; double result = 0; for ( counter = 0; counter < length - 1; counter++ ) { sum += price[counter]; } if ( length > 0 ) { result = sum / length; } if ( debug ) { logOutput( StringConcatenate( " - calculateAverage() return: ", result ) ); } return( result ); } // Write information to the experts log with date and version of the caller void logOutput( string logText ) { Print( NAME, " (", VERSION, ") ", TimeToStr( CurTime(), TIME_DATE|TIME_MINUTES|TIME_SECONDS ), logText ); } /* ------------------------------------------------------------------ */ /* Helper Routine for calling the Average with the functionality */ /* from the original Easy Language */ /* ------------------------------------------------------------------ */ // This function builds an array with the calulation of ( high + low ) / 2 // in the given length. // the values are taken from the periods at shift and before // double calculateAverageHelper( double price1[], double price2[], int length, int shift ) { double value[]; int i; int j; double result; if ( debug ) { logOutput( StringConcatenate( " - calculateAverageHelper() inputs - price1[0]: ", price1[0], ", price2[", shift, "]: ", price2[shift], " length: ", length, ", shift: ", shift ) ); } ArrayResize( value, length ); for ( i = 0; i < length; i++ ) { j = i + shift; value[i] = ( price1[j] + price2[j] ) / 2; } result = calculateAverage( value, length ); if ( debug ) { logOutput( StringConcatenate( " - calculateAverageHelper() return: ", result ) ); } return( result ); }I don't understand, why I get in the downFrac -1 and therefore, the line isn't painted. I have looked at the code again and again and can not find it.
Alexantry, please can you put some prints in your code, which are printing all the calculatet values on each run, so like value0 thru value4, the bl-lines etc. Post the protocol here, so that I maybe can see, what is happening.
greetings, cori
// function Average as provided from Alexantry
//
double calculateAverage( double price[], int length ) {
/*******************************************************************
Description: Simple Moving Average
Provided By: Omega Research, Inc. (c) Copyright 1999
********************************************************************/
if ( debug ) {
logOutput( StringConcatenate( " - calculateAverage() inputs - price[0]: ", price[0],
", length: ", length ) );
}
double sum = 0;
int counter = 0;
double result = 0;
//HDB this loop misses one value: if length is 3, length-1 is 2 and the for loop does 0, 1 whereas it should do 0,1,2
for ( counter = 0; counter < length - 1; counter++ ) {
sum += price[counter];
}
if ( length > 0 ) {
result = sum / length;
}
if ( debug ) {
logOutput( StringConcatenate( " - calculateAverage() return: ", result ) );
}
return( result );
}
anyway, its late so good night and have a nice weekend !
I have corrected the loop and the second line also shows up.
I don't know what it calculates, really not, but it was a good example to learn Easy Language, I now have a reference book - downloaded from tradestation.com. Some things in there are for the programmers, which write code to forget, because it gets difficult to understand like the example I gave above with the [x] behind the function.
BTW: my favorite indicator is the Ichimoku Kinko Hyo.
Ok, lets go. Alexantry, check if it might do what you expect. Compare it to your tradestation or whatever you have.
Picture ( USDJPY )
The code. Make a new custom indicator, name it as you want, and paste it there. - Ah, and don't forget to read the header of the code ;-)
/* ****************************************************************** */ /* ABillW_ActiveFractal */ /* ------------------------------------------------------------------ */ /* I dont understand what is calculated here. All I have is a */ /* badly documented programming example */ /* */ /* Copyright and pricing */ /* */ /* This code was developed by coriFX 2005. */ /* */ /* You can use this code to make money as much as you wish without */ /* fee. If you have made your first million using my code, I would */ /* ask you to send me 10%. contact me at { corifx at o2go dot de }. */ /* I will send you the information for money transfer. */ /* */ /* ****************************************************************** */ #property copyright "developed by coriFX 2005" //---- indicator settings #property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 Blue #property indicator_color2 Red // Indicator buffer double bufUpFrac[]; double bufDownFrac[]; /* ------------------------------------------------------------------ */ /* Definitionen of Standardvalues */ /* ------------------------------------------------------------------ */ #define NAME "ABillW_ActiveFractal" #define VERSION "1.0" /* ------------------------------------------------------------------ */ /* Includes */ /* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */ /* Imported functions and used libraries */ /* ------------------------------------------------------------------ */ #import /* ------------------------------------------------------------------ */ /* Parameters */ /* ------------------------------------------------------------------ */ extern int maxFracsBack = 10; extern bool debug = false; /* ------------------------------------------------------------------ */ /* Initialize */ /* ------------------------------------------------------------------ */ int init() { logOutput( ": initialize" ); if ( debug ) { logOutput( "-----> Debug enabled" ); } // initialize indicator IndicatorShortName( NAME ); SetIndexStyle( 0, DRAW_LINE ); SetIndexLabel( 0, "upFrac" ); if ( ! SetIndexBuffer( 0, bufUpFrac ) ) { logOutput( "cannot set Index Buffer 0" ); } SetIndexStyle( 1, DRAW_LINE ); SetIndexDrawBegin( 1, 20 ); SetIndexLabel( 1, "downFrac" ); if ( ! SetIndexBuffer( 1, bufDownFrac ) ) { logOutput( "cannot set Index Buffer 1" ); } return( 0 ); } /* ------------------------------------------------------------------ */ /* End. Free all resources */ /* ------------------------------------------------------------------ */ int deinit() { logOutput( ": deinitialize" ); return( 0 ); } /* ------------------------------------------------------------------ */ /* Main routine. Called at every tick */ /* ------------------------------------------------------------------ */ int start() { int counted = IndicatorCounted(); int remain = Bars - counted; int i; logOutput( StringConcatenate( ": start new cycle - counted: ", counted, ", remain: ", remain ) ); if ( counted < 0 ) { return( -1 ); } for ( i = 0; i < remain; i++ ) { calculateIndicatorValues( i ); } if ( debug ) { for ( i = 0; i < remain; i++ ) { logOutput( StringConcatenate( ": Buffers - bufUpFrac[", i, "] = ", bufUpFrac[i], ", bufDownFrac[", i, "] = ", bufDownFrac[i] ) ); } } } // Function to calculate the indicator values void calculateIndicatorValues( int shift ) { double upFrac = 0; double dnFrac = 0; bool stp_now = false; int i1 = 1; double value1 = High[Highest( Symbol(), 0, MODE_HIGH, 3, shift )]; double value2 = Low[Lowest( Symbol(), 0, MODE_LOW, 3, shift )]; double value3 = 0; double value4 = 0; double blBlue = calculateAverageHelper( High, Low, 13, 8 + shift ); // {blue} double blRed = calculateAverageHelper( High, Low, 8, 5 + shift ); // {red} double blGreen = calculateAverageHelper( High, Low, 5, 3 + shift ); // {green} // int values for calculation int intValue1 = MathRound( value1 / Point ); int intValue2 = MathRound( value2 / Point ); int intValue3 = 0; int intValue4 = 0; int intBlBlue = MathRound( blBlue / Point ); int intBlRed = MathRound( blRed / Point ); int intBlGreen = MathRound( blGreen / Point ); if ( debug ) { logOutput( StringConcatenate( " - calculateIndicatorValues() - shift: ", shift, ", value1: ", value1, ", value2: ", value2, ", blBlue: ", blBlue, ", blRed: ", blRed, ", blGreen: ", blGreen ) ); } // Wenn dnFrac ueber blred liegt, dann ist es ungueltig // das vorhergehende frac wird dann getestet usw. stp_now = false; i1 = 1; value3 = calculateSwingLow( i1, Low, 2, 80, shift ); while ( i1 < maxFracsBack && value3 != -1 && ! stp_now ) { intValue3 = MathRound( value3 / Point ); if ( intValue3 > intBlRed || intValue3 > intValue2 ) { i1 += 1; value3 = calculateSwingLow( i1, Low, 2, 80, shift ); } else { stp_now = TRUE; } } if ( stp_now ) { dnFrac = value3; } else { dnFrac = -1; } if ( i1 >= maxFracsBack ) { logOutput( StringConcatenate( ": ", i1 ," mehr als ", maxFracsBack, " dnFracs" ) ); } // Wenn upFrac unter blRed liegt, ist es ungueltig. // Das vorhergehende upFrac wird dann auf Gueltigkeit getestet usw. stp_now = false; i1 = 1; value4 = calculateSwingHigh( i1, High, 2, 80, shift ); while ( i1 < maxFracsBack && value4 != -1 && ! stp_now ) { intValue4 = MathRound( value4 / Point ); if ( intValue4 < intBlRed || intValue4 < intValue1 ) { i1 += 1; value4 = calculateSwingHigh( i1, High, 2, 80, shift ); } else { stp_now = TRUE; } // I think this statement is not necessary // if date=930219 then print(d," ooh ",i1,stp_now,value4); } if ( stp_now ) { upFrac = value4; } else { upFrac = -1; } if ( i1 >= maxFracsBack ) { logOutput( StringConcatenate( ": ", i1 ," mehr als ", maxFracsBack, " upFracs" ) ); } logOutput( StringConcatenate( ": upFrac: ", upFrac, ", downFrac: ", dnFrac ) ); if ( upFrac != 0 && upFrac != -1 ) { bufUpFrac[shift] = upFrac; } else { bufUpFrac[shift] = bufUpFrac[shift - 1]; } if ( dnFrac != 0 && dnFrac != -1 ) { bufDownFrac[shift] = dnFrac; } else { bufDownFrac[shift] = bufDownFrac[shift - 1]; } return; } /* ------------------------------------------------------------------ */ /* Internal routines */ /* ------------------------------------------------------------------ */ // function SwingHigh as provided from Alexantry // double calculateSwingHigh( int occur, double price[], int strength, int length, int shift ) { /******************************************************************* Description: Swing High Provided By: Omega Research, Inc. (c) Copyright 1999 ********************************************************************/ int x = 0; int j = strength; int counter = 0; double price1 = 0; bool found = false; bool truth = false; // Fields for calculation int intPrice1; int intPriceX; if ( debug ) { logOutput( StringConcatenate( " - calculateSwingHigh() inputs - occur: ", occur, ", price[", shift, "]: ", price[shift], ", strength: ", strength, ", length: ", length, ", shift: ", shift ) ); } if ( j > 0 ) { counter = 0; while ( j < length && ! found ) { price1 = price[j + shift]; x = j + 1; truth = true; while ( truth && ( x - j ) <= strength ) { intPrice1 = MathRound( price1 / Point ); intPriceX = MathRound( price[x + shift] / Point ); if ( intPrice1 < intPriceX ) { truth = false; } x += 1; } x = j - 1; while ( truth && ( j - x ) <= strength ) { intPrice1 = MathRound( price1 / Point ); intPriceX = MathRound( price[x + shift] / Point ); if ( intPrice1 <= intPriceX ) { truth = false; } x -= 1; } if ( truth ) { counter += 1; } if ( counter >= occur ) { found = true; } j += 1; } } if ( ! found ) { price1 = -1; } if ( debug ) { logOutput( StringConcatenate( " - calculateSwingHigh() return: ", price1 ) ); } return( price1 ); } // function SwingLow as provided from Alexantry // double calculateSwingLow( int occur, double price[], int strength, int length, int shift ) { /******************************************************************* Description: Swing Low Provided By: Omega Research, Inc. (c) Copyright 1999 ********************************************************************/ int x = 0; int j = strength; int counter = 0; double price1 = 0; bool found = false; bool truth = false; // Fields for calculation int intPrice1; int intPriceX; if ( debug ) { logOutput( StringConcatenate( " - calculateSwingLow() inputs - occur: ", occur, ", price[", shift, "]: ", price[shift], ", strength: ", strength, ", length: ", length, ", shift: ", shift ) ); } if ( j > 0 ) { counter = 0; while ( j < length && ! found ) { price1 = price[j + shift]; x = j + 1; truth = true; while ( truth && ( x - j ) <= strength ) { intPrice1 = MathRound( price1 / Point ); intPriceX = MathRound( price[x + shift] / Point ); if ( intPrice1 > intPriceX ) { truth = false; } x += 1; } x = j - 1; while ( truth && ( j - x ) <= strength ) { intPrice1 = MathRound( price1 / Point ); intPriceX = MathRound( price[x + shift] / Point ); if ( intPrice1 >= intPriceX ) { truth = false; } x -= 1; } if ( truth ) { counter += 1; } if ( counter >= occur ) { found = true; } j += 1; } } if ( ! found ) { price1 = -1; } if ( debug ) { logOutput( StringConcatenate( " - calculateSwingLow() return: ", price1 ) ); } return( price1 ); } // function Average as provided from Alexantry // double calculateAverage( double price[], int length ) { /******************************************************************* Description: Simple Moving Average Provided By: Omega Research, Inc. (c) Copyright 1999 ********************************************************************/ if ( debug ) { logOutput( StringConcatenate( " - calculateAverage() inputs - price[0]: ", price[0], ", length: ", length ) ); } double sum = 0; int counter = 0; double result = 0; // Thanks HDB for finding my mistake interpreting a "For" loop for ( counter = 0; counter < length; counter++ ) { sum += price[counter]; } if ( length > 0 ) { result = sum / length; } if ( debug ) { logOutput( StringConcatenate( " - calculateAverage() return: ", result ) ); } return( result ); } // Write information to the experts log with date and version of the caller void logOutput( string logText ) { Print( NAME, " (", VERSION, ") ", TimeToStr( CurTime(), TIME_DATE|TIME_MINUTES|TIME_SECONDS ), logText ); } /* ------------------------------------------------------------------ */ /* Helper Routine for calling the Average with the functionality */ /* from the original Easy Language */ /* ------------------------------------------------------------------ */ // This function builds an array with the calulation of ( high + low ) / 2 // in the given length. // the values are taken from the periods at shift and before // double calculateAverageHelper( double price1[], double price2[], int length, int shift ) { double value[]; int i; int j; double result; if ( debug ) { logOutput( StringConcatenate( " - calculateAverageHelper() inputs - price1[0]: ", price1[0], ", price2[", shift, "]: ", price2[shift], " length: ", length, ", shift: ", shift ) ); } ArrayResize( value, length ); for ( i = 0; i < length; i++ ) { j = i + shift; value[i] = ( price1[j] + price2[j] ) / 2; } result = calculateAverage( value, length ); if ( debug ) { logOutput( StringConcatenate( " - calculateAverageHelper() return: ", result ) ); } return( result ); }Good luck, and again, thank you, hugues.
cori
EDIT: I have set the debug Switch to false. If not it would fill up your log with garbage.