Convert Solar wind joy mt4 indicator to AFL

#12
Dear sir
The intraday trading technique is when histogram crosses zero line from below and it forms green bar. After formation of second green bar we should take buy entry and vice-versa is for sell call.
Timeframe 15 minute for intraday and 60 minutes for positional.
 

KelvinHand

Well-Known Member
#13
PHP:
/***************************************
 Solar Wind Joy Translated from MT4 to Amibroker
 Done by KelvinHand
****************************************/
Version(4.90);


period = Param("Period",35, 1);
smooth = Param("Smooth",10, 1);


MaxHHV = HHV(H, period);
MinLLV = LLV(L, period);

Value1=0;
Fish1=0;

aFish=Null;

for(i=0; i<BarCount; i++)
{
    MaxH = MaxHHV[i];
    MinL = MinLLV[i];
    Price = (H[i]+L[i])/2;
       
	Value = 0.33*2*((Price-MinL)/(MaxH-MinL)-0.5)+0.67*Value1;
	Value = Min(Max(Value, -0.999), 0.999);
	
	aFish[i] = 0.5*log((1+Value)/(1-Value))+0.5*Fish1;
	
	Value1 = Value;
	Fish1 = aFish[i];
	
	if (aFish[i]>0)
	   aFish[i]=10;
	else
	   aFish[i]=-10;
}


aSmth=0;

for(i=0; i<BarCount; i++)
{
  SumI=0;
  SumW=0;
  
  for(k=0; k<smooth && (i-k)>=0; k++)
  {
     weight = smooth-k;
     SumW += weight;
     SumI += weight*aFish[i-k];
  }
     
   if (SumW>0)
      aSmth[i] = SumI/SumW;     
  
}

aLine=0;
for(i=0; i<BarCount; i++)
{
  SumI=0;
  SumW=0;
  
  for(k=0; k<smooth && (i-k)>=0; k++)
  {
     weight = smooth-k;
     SumW += weight;
     SumI += weight*aSmth[i-k];
  }
     
   if (SumW>0)
      aLine[i] = SumI/SumW;     
   
}


colorH = IIf(aLine>0, colorBrightGreen, IIf(aLine<0, colorRed, colorGold));
Plot(aLine, "", colorH, stylenolabel|styleHistogram);

colorL = IIf(aLine>0 AND Ref(aLine, -1)>0, colorBrightGreen, IIf(aLine<0 AND Ref(aLine, -1) <0, colorRed, colorGold));
Plot(aLine, "", colorL, stylenolabel|stylethick);



PlotGrid(0, colorLightgrey, 6, 1, True);
 
#14
Dear Kelvin Sir
Thanks a million for such a nice help.
You are a great person , i say a millions of thanks to you from the bottom of my heart .
You solved my problem in a couple of days .
:clap::clap::clap::clap::clap:
:clapping::clapping::clapping::clapping::clapping:
 

krab

Active Member
#15
PHP:
/***************************************
 Solar Wind Joy Translated from MT4 to Amibroker
 Done by KelvinHand
****************************************/
Version(4.90);


period = Param("Period",35, 1);
smooth = Param("Smooth",10, 1);


MaxHHV = HHV(H, period);
MinLLV = LLV(L, period);

Value1=0;
Fish1=0;

aFish=Null;

for(i=0; i<BarCount; i++)
{
    MaxH = MaxHHV[i];
    MinL = MinLLV[i];
    Price = (H[i]+L[i])/2;
       
	Value = 0.33*2*((Price-MinL)/(MaxH-MinL)-0.5)+0.67*Value1;
	Value = Min(Max(Value, -0.999), 0.999);
	
	aFish[i] = 0.5*log((1+Value)/(1-Value))+0.5*Fish1;
	
	Value1 = Value;
	Fish1 = aFish[i];
	
	if (aFish[i]>0)
	   aFish[i]=10;
	else
	   aFish[i]=-10;
}


aSmth=0;

for(i=0; i<BarCount; i++)
{
  SumI=0;
  SumW=0;
  
  for(k=0; k<smooth && (i-k)>=0; k++)
  {
     weight = smooth-k;
     SumW += weight;
     SumI += weight*aFish[i-k];
  }
     
   if (SumW>0)
      aSmth[i] = SumI/SumW;     
  
}

aLine=0;
for(i=0; i<BarCount; i++)
{
  SumI=0;
  SumW=0;
  
  for(k=0; k<smooth && (i-k)>=0; k++)
  {
     weight = smooth-k;
     SumW += weight;
     SumI += weight*aSmth[i-k];
  }
     
   if (SumW>0)
      aLine[i] = SumI/SumW;     
   
}


colorH = IIf(aLine>0, colorBrightGreen, IIf(aLine<0, colorRed, colorGold));
Plot(aLine, "", colorH, stylenolabel|styleHistogram);

colorL = IIf(aLine>0 AND Ref(aLine, -1)>0, colorBrightGreen, IIf(aLine<0 AND Ref(aLine, -1) <0, colorRed, colorGold));
Plot(aLine, "", colorL, stylenolabel|stylethick);



PlotGrid(0, colorLightgrey, 6, 1, True);
Thank you for your afl, I am getting error in the following line The error says Too many arguments. I am using amibroker version 5.7.2. please solve the problem

PlotGrid(0, colorLightGrey, 6, 1, True);
 
#16
Thank you for your afl, I am getting error in the following line The error says Too many arguments. I am using amibroker version 5.7.2. please solve the problem
Comment out that line or use

Plot(0, "", colorLightGrey", 1);



Thanks KelvinHand for the code

First look seems a very good oscillator . . .

Using higher param values introduces some lag but nicely smooths out the whipsaws


Thanks
 

KelvinHand

Well-Known Member
#17
Thank you for your afl, I am getting error in the following line The error says Too many arguments. I am using amibroker version 5.7.2. please solve the problem

PlotGrid(0, colorLightGrey, 6, 1, True);

I already stated the version 4.90. I don't want keep bother down by your old version.
You need to solve your own problem yourself or upgrade to the latest version.

Otherwise, we will never advance ourself at all.
 
#18
Can somebody who has reviewed this comment on
- Best Timeframe
- Entry and exit strategy.

I read that it was for 15 mins and entry above the 2nd candle high for longs,
 

trash

Well-Known Member
#19
PHP:
/***************************************
 Solar Wind Joy Translated from MT4 to Amibroker
 Done by KelvinHand
****************************************/
Version(4.90);


period = Param("Period",35, 1);
smooth = Param("Smooth",10, 1);


MaxHHV = HHV(H, period);
MinLLV = LLV(L, period);

Value1=0;
Fish1=0;

aFish=Null;

for(i=0; i<BarCount; i++)
{
    MaxH = MaxHHV[i];
    MinL = MinLLV[i];
    Price = (H[i]+L[i])/2;
       
	Value = 0.33*2*((Price-MinL)/(MaxH-MinL)-0.5)+0.67*Value1;
	Value = Min(Max(Value, -0.999), 0.999);
	
	aFish[i] = 0.5*log((1+Value)/(1-Value))+0.5*Fish1;
	
	Value1 = Value;
	Fish1 = aFish[i];
	
	if (aFish[i]>0)
	   aFish[i]=10;
	else
	   aFish[i]=-10;
}


aSmth=0;

for(i=0; i<BarCount; i++)
{
  SumI=0;
  SumW=0;
  
  for(k=0; k<smooth && (i-k)>=0; k++)
  {
     weight = smooth-k;
     SumW += weight;
     SumI += weight*aFish[i-k];
  }
     
   if (SumW>0)
      aSmth[i] = SumI/SumW;     
  
}

aLine=0;
for(i=0; i<BarCount; i++)
{
  SumI=0;
  SumW=0;
  
  for(k=0; k<smooth && (i-k)>=0; k++)
  {
     weight = smooth-k;
     SumW += weight;
     SumI += weight*aSmth[i-k];
  }
     
   if (SumW>0)
      aLine[i] = SumI/SumW;     
   
}


colorH = IIf(aLine>0, colorBrightGreen, IIf(aLine<0, colorRed, colorGold));
Plot(aLine, "", colorH, stylenolabel|styleHistogram);

colorL = IIf(aLine>0 AND Ref(aLine, -1)>0, colorBrightGreen, IIf(aLine<0 AND Ref(aLine, -1) <0, colorRed, colorGold));
Plot(aLine, "", colorL, stylenolabel|stylethick);



PlotGrid(0, colorLightgrey, 6, 1, True);
Not being interested in this indicator but just for fun...
The entire code can be significantly optimized to higher speed performance using AMA2 function instead of first loop and averaging code part (2nd loop) may use visible chart area etc.

For example just compare the higher responsiveness if you insert the two AFL versions into a chart pane (one pane per AFL). Then you will see that the difference is huge on tens of thousands of bars and more.

BTW, you mean 5.90 not 4.90. 4.90 is of year 2007. ;)


Code:
/*************************************** 
 Solar Wind Joy Translated from MT4 to Amibroker 
 heavily modified by trash to significantly improve speed of original code by KelvinHand
 origins from http://www.traderji.com/amibroker/98121-convert-solar-wind-joy-mt4-indicator-afl-2.html 
****************************************/
Version( 5.90 );

period = Param( "Period", 35, 1 );
smooth = Param( "Smoothing period", 10, 1 );

//---- mod by trash start
// using AMA2 -> huge speed up by using array instead of loop
function aFishFunc( period ) {
    MaxH = HHV( H, period );
    MinL = LLV( L, period );
    midbar = ( H + L ) / 2;
    
    array1  = 2 * ( ( midbar - MinL ) / ( MaxH - MinL + 1e-30 ) - 0.5 );
    Value = AMA2( array1, 0.33, 0.67 );
    Value = Min( Max( Value, -0.999 ), 0.999 );

    array2 = log( ( 1 + Value ) / ( 1 - Value ) );
    aFish = AMA2( array2, 0.5, 0.5 );
    return IIf( aFish > 0, 10, -10 );
}

function VarSum( per ) {
    result = per;
    for( i = 1; i < per; i++ )
        result += per - i;
    return result;
}

// two times used average calculation put to function
function cAverage( array, period ) {
    bi = BarIndex();
    if( Status( "action" ) == actionIndicator ) {
        startbar = Max( period, FirstVisibleValue( bi ) - period );
        endbar = LastVisibleValue( bi );
    } else {
        startbar = period;
        endbar = BarCount - 1;
    }
    //
    result = Null;
    for( i = startbar; i <= endbar; i++ ) {
        SumI = 0;
        for( k = 0; k < period; k++ ) {
            weight = period - k;
            SumI += weight * array[i - k];
        }
        result[i] = SumI;
    }
    return result / VarSum( period );
}

aFish = aFishFunc( period );
aLine = cAverage( cAverage( aFish, smooth ), smooth );
// --- mod by trash end


colorH = IIf( aLine > 0, colorBrightGreen, 
         IIf( aLine < 0, colorRed, colorGold ) );
Plot( aLine, "", colorH, stylenolabel | styleHistogram, Null, Null, 0, 0, -30 );

colorL = IIf( /*mod by trash*/Sum(aLine > 0, 2) == 2, colorBrightGreen, 
         IIf( /*mod by trash*/Sum(aLine < 0, 2) == 2, colorRed, colorGold ) );
Plot( aLine, "", colorL, stylenolabel | stylethick );

PlotGrid( 0, colorLightgrey, 6, 1, True );

Title = StrFormat( "{{NAME}} - {{INTERVAL}} - Solar Wind Joy: " +
                   EncodeColor( SelectedValue( ColorL ) ) + "%g", aline );
 

Similar threads