My Trading Strategy Needs Coding

#1
Hi,

Below is my simple strategy. Request to write AFL for same. AFLs of the components are available on net and on Traderji.

I buy when Volume Zone Oscillator, VWAP and SuperTrend all are positively in Buy Mode. And do wait for reverse signals on all 3 to initiate a Short.

Tried to put all three conditions as a ribbon on my chart to remove all clutter. But i do not know how to "hold" a signal until reverse signal appears.

I have created a small Algorithm which if coded correctly can give desired results. Below, have a look.

===================================
**********************BEGIN**************************
===================================


Initial Declare / Asssign values to flags
greenflagup = 0;
yellowflagup = 0;
redflagup =0;


if at end of most current bar ---> ((buy1 and buy2 and buy3) are all true) AND ((sell1 and sell2 and sell3) are all false);
greenflagup = 1;
(( ACTION -- color of all bars to remain GREEN from CURRENT BAR ONWARDS) uptill greenflagup = 1);


if at the end of current bar ---> (EITHER OF ( Sell1 or Sell2 or Sell3) are true (BUT NOT ALL TRUE TOGETHER, that is, (Sell1 and Sell2 and Sell3 ) != TRUE);
greenflagup = 0;
yellowflagup = 1;
(( ACTION -- color of all bars to remain GREY from CURRENT BAR ONWARDS) uptill yellowflagup = 1);


if at end of most current bar ---> ((Sell1 and Sell2 and Sell3 ) are all true) AND ((buy1 and buy2 and buy3) are all false);
redflagup = 1;
(( ACTION -- color of all bars to remain RED from CURRENT BAR ONWARDS) uptill REDflagup = 1);


if at the end of current bar ---> (EITHER OF ( buy1 OR buy2 OR buy3) are true (BUT NOT ALL TRUE TOGETHER, that is, ( buy1 AND buy2 AND buy3 ) != TRUE);
redflagup = 0;
yellowflagup = 1;
(( ACTION -- color of all bars to remain GREY from CURRENT BAR ONWARDS) uptill yellowflagup = 1);


===================================
***********************END***************************
===================================

Request to write AFL for same.
 

radiosilk

Active Member
#2
Hi,

I have tried my best and have tried coding (where i have no idea of development and coding). May be i coded all wrong. Tried and failed with "for loops", "lastvalue" and now failed with "value when".

Could you please suggest how to combine different indicator signals that appear on different bars, into one.

I will be much obliged.

PHP:
Buy =   (ValueWhen(Buy1,Buy1)==1 AND ValueWhen(Buy2,Buy2)==1 AND ValueWhen(Buy3,Buy3)==1) AND (ValueWhen(Sell1,Sell1)  ==0 AND ValueWhen(Sell2,Sell2) == 0 AND ValueWhen(Sell3,Sell3) ==0); 
Sell =   (ValueWhen(Sell1,Sell1)==1 AND ValueWhen(Sell2,Sell2)==1 AND ValueWhen(Sell3,Sell3)==1) AND (ValueWhen(Buy1,Buy1)  == 0 AND ValueWhen(Buy2,Buy2) ==0 AND  ValueWhen(Buy3,Buy3) ==0); 

sideways = ((ValueWhen(Buy1,Buy1)==1 AND ValueWhen(Buy2,Buy2)==1 AND ValueWhen(Buy3,Buy3)==1) AND (ValueWhen(Sell1,Sell1)==1 OR ValueWhen(Sell2,Sell2)==1 OR ValueWhen(Sell3,Sell3) ==1)) 
        OR    ((ValueWhen(Sell1,Sell1)==1 AND ValueWhen(Sell2,Sell2)==1 AND ValueWhen(Sell3,Sell3)==1) AND (ValueWhen(Buy1,Buy1)==1 OR ValueWhen(Buy2,Buy2)==1 OR  ValueWhen(Buy3,Buy3) ==1)) 
     OR    ((ValueWhen(Sell1,Sell1) ==1 OR ValueWhen(Sell2,Sell2)==1 OR  ValueWhen(Sell3,Sell3)==1) AND (ValueWhen(Buy1,Buy1)==1 OR ValueWhen(Buy2,Buy2) OR ValueWhen(Buy3,Buy3) ==1));
 

radiosilk

Active Member
#4
Without seeing your complete code and a chart it is difficult to understand your problem.

(code has been commented upon a lot by me. It might help to copy paste it in amibroker to understand it. )

please do help. looking forward to your guidance.
=================
PHP:
_SECTION_BEGIN( "Confluence" );
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////Volume Zone Oscillator/////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////


//Volume Zone Oscillator 
C1=C;
V1=V;
period=Param("LookBack",14,2,999,1,0);
R= IIf (C1>Ref(C1,-1), V1,-V1); 
VP= EMA (R, period);
TV=EMA (V, period);
VZO= 100*(VP/TV);
//Plot(VZO,"",colorOrange,4);
//Plot(60,"",colorPaleBlue,styleLine);
//Plot(40,"",colorPaleBlue,styleLine);
//Plot(0,"",colorDefault,styleDashed);
//Plot(-60,"",colorPaleBlue,styleLine);
//Plot(-40,"",colorPaleBlue,styleLine);
//PlotOHLC(Null,60,40,Null,"",colorDarkGreen);//Removed stylecloud
//PlotOHLC(Null,-60,-40,Null,"",colorDarkRed); //Removed styleCloud

  
///////////////////////////////buy/sell///////////////////////
//zerochkbuy = IIf(Cross(0,Ref(VZO,-1)) AND Cross(VZO,0),True,False);
//zerochksell = IIf(Cross(Ref(VZO,-1),0)AND Cross(0,VZO),True,False);

//Buy=Cross(VZO,-40) OR zerochkbuy;Sell=Cross(40,VZO) OR zerochksell ;
Buy1=Cross(VZO,-40) OR Cross(VZO,0);
Sell1=Cross(40,VZO) OR Cross(0,VZO);
//Buy = ExRem( Buy, Sell );
//Sell = ExRem( Sell, Buy );
/////////////////////////shapes ///////////////////////////////
//shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
//PlotShapes( shape, IIf( Buy, colorBrightGreen, colorRed ),0, IIf( Buy,VZO,VZO) );
/////////////////////////exploration ///////////////////////////////
//Filter=Buy OR Sell; 
//AddColumn( IIf(Buy,1,IIf(Sell,-1,Null)) ,"B/S",1.0,colorWhite,IIf(Buy,colorGreen,IIf(Sell,colorRed,Null)),60);
  
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////Volume Zone Oscillator/////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////



///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////SuperTrend ATR System///////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
    Factor = Param( "Factor", 1, 1, 10, 0.1 );
    Pd = Param( "ATR Periods", 5, 1, 100, 1 );

    Up = ( H + L ) / 2 + ( Factor * ATR( Pd ) );
    Dn = ( H + L ) / 2 - ( Factor * ATR( Pd ) );
    iATR = ATR( Pd );
    TrendUp = TrendDown = Null;
    trend[0] = 1;
    changeOfTrend = 0;
    flag = flagh = 0;

    for ( i = 1; i < BarCount - 1; i++ )
    {
        TrendUp[i] = Null;
        TrendDown[i] = Null;

        trend[i] = 1;


        if ( Close[i] > Up[i-1] )
        {
            trend[i] = 1;

            if ( trend[i-1] == -1 )
                changeOfTrend = 1;

        }
        else
            if ( Close[i] < Dn[i-1] )
            {
                trend[i] = -1;

                if ( trend[i-1] == 1 )
                    changeOfTrend = 1;
            }
            else
                if ( trend[i-1] == 1 )
                {
                    trend[i] = 1;
                    changeOfTrend = 0;
                }
                else
                    if ( trend[i-1] == -1 )
                    {
                        trend[i] = -1;
                        changeOfTrend = 0;
                    }

        if ( trend[i] < 0 && trend[i-1] > 0 )
        {
            flag = 1;
        }
        else
        {
            flag = 0;
        }

        if ( trend[i] > 0 && trend[i-1] < 0 )
        {
            flagh = 1;
        }
        else
        {
            flagh = 0;
        }

        if ( trend[i] > 0 && Dn[i] < Dn[i-1] )
        {
            Dn[i] = Dn[i-1];
        }

        if ( trend[i] < 0 && Up[i] > Up[i-1] )
        {
            Up[i] = Up[i-1];
        }

        if ( flag == 1 )
        {
            Up[i] = ( H[i] + L[i] ) / 2 + ( Factor * iATR[i] );;
        }

        if ( flagh == 1 )
        {
            Dn[i] = ( H[i] + L[i] ) / 2 - ( Factor * iATR[i] );;
        }

        if ( trend[i] == 1 )
        {
            TrendUp[i] = Dn[i];

            if ( changeOfTrend == 1 )
            {
                TrendUp[i-1] = TrendDown[i-1];
                changeOfTrend = 0;
            }
        }
        else
            if ( trend[i] == -1 )
            {
                TrendDown[i] = Up[i];

                if ( changeOfTrend == 1 )
                {
                    TrendDown[i-1] = TrendUp[i-1];
                    changeOfTrend = 0;
                }
            }
    }

//    Plot( TrendUp, "Trend", colorBrightGreen , styleNoRescale);

//    Plot( TrendDown, "Down", colorRed , styleNoRescale);

    
    

//////////////////////////////SuperTrend BUY CONDITIONS///////////////////////////////////////////////////////////
Buy2 = IIf(trend == 1,1,0);
//////////////////////////////SuperTrend SELL CONDITIONS////////////////////////////////////
Sell2 = IIf(trend == -1,1,0);
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////



///////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////VWAP CALCULATIONS////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////


starttime = 093000; 
endtime = 160000; 

timeWindow = TimeNum() >= starttime AND TimeNum() <= endtime;
firstBarOfDay = TimeNum() >= starttime ;
firstBarOfDay = firstBarOfDay - Ref(firstBarOfDay,-1);

P = (H + L)/2;

vv = V * P * timeWindow;

BarsInDay = (1 + BarsSince(firstBarOfDay)) * timeWindow;
CumVolumeInDay = Sum(V,BarsInDay);
VWAP = Sum(vv, BarsInDay ) / CumVolumeInDay;
SV = Sum((P - VWAP)^2,BarsInDay) / BarsInDay; // sample variance
SD = sqrt(SV); // standard deviation
period = ParamList( "What period?", "Daily|Weekly|Monthly", 0 );

switch ( period )
{

case "Daily":
    newPeriod = Day() != Ref( Day(), -1 );
    break;

case "Weekly":
    newPeriod = DayOfWeek() == 0 AND Ref( DayOfWeek(), -1 ) != 0;
    break;

case "Monthly":
    newPeriod = Month() != Ref( Month(), -1 );
    break;
}
//////////////////////////////VWAP BUY CONDITIONS///////////////////////////////////////////////////////////
Buy3 = Ref(C,-1) > VWAP ;    
//////////////////////////////VWAP SELL CONDITIONS///////////////////////////////////////////////////////////
Sell3 = Ref(C,-1) < VWAP ;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////Buy Sell Logic///////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
Buy =   (ValueWhen(Buy1,Buy1)==1 AND ValueWhen(Buy2,Buy2)==1 AND ValueWhen(Buy3,Buy3)==1) AND (ValueWhen(Sell1,Sell1)  ==0 AND ValueWhen(Sell2,Sell2) == 0 AND ValueWhen(Sell3,Sell3) ==0);
Sell =   (ValueWhen(Sell1,Sell1)==1 AND ValueWhen(Sell2,Sell2)==1 AND ValueWhen(Sell3,Sell3)==1) AND (ValueWhen(Buy1,Buy1)  == 0 AND ValueWhen(Buy2,Buy2) ==0 AND  ValueWhen(Buy3,Buy3) ==0);

sideways = ((ValueWhen(Buy1,Buy1)==1 AND ValueWhen(Buy2,Buy2)==1 AND ValueWhen(Buy3,Buy3)==1) AND (ValueWhen(Sell1,Sell1)==1 OR ValueWhen(Sell2,Sell2)==1 OR ValueWhen(Sell3,Sell3) ==1))
        OR    ((ValueWhen(Sell1,Sell1)==1 AND ValueWhen(Sell2,Sell2)==1 AND ValueWhen(Sell3,Sell3)==1) AND (ValueWhen(Buy1,Buy1)==1 OR ValueWhen(Buy2,Buy2)==1 OR  ValueWhen(Buy3,Buy3) ==1))
     OR    ((ValueWhen(Sell1,Sell1) ==1 OR ValueWhen(Sell2,Sell2)==1 OR  ValueWhen(Sell3,Sell3)==1) AND (ValueWhen(Buy1,Buy1)==1 OR ValueWhen(Buy2,Buy2) OR ValueWhen(Buy3,Buy3) ==1));




//Buy =   (LastValue(Buy1)==1 AND LastValue(Buy2)==1 AND LastValue(Buy3)==1) AND (LastValue(Sell1)  ==0 AND LastValue(Sell2) == 0 AND LastValue(Sell3) ==0);
//Sell =   (LastValue(Sell1)==1 AND LastValue(Sell2)==1 AND LastValue(Sell3)==1) AND (LastValue(Buy1)  == 0 AND LastValue(Buy2) ==0 AND  LastValue(Buy3) ==0);

//sideways = ((LastValue(Buy1)==1 AND LastValue(Buy2)==1 AND LastValue(Buy3)==1) AND (LastValue(Sell1)==1 OR LastValue(Sell2)==1 OR LastValue(Sell3) ==1))
   //     OR    ((LastValue(Sell1)==1 AND LastValue(Sell2)==1 AND LastValue(Sell3)==1) AND (LastValue(Buy1)==1 OR LastValue(Buy2)==1 OR  LastValue(Buy3) ==1))
     //OR    ((LastValue(Sell1) ==1 OR LastValue(Sell2)==1 OR  LastValue(Sell3)==1) AND (LastValue(Buy1)==1 OR LastValue(Buy2) OR LastValue(Buy3) ==1));


//Buy =   (LastValue(VWAPbuyflag)==LastValue(vzobuyflag)==LastValue(SupTbuyflag)==1) AND (LastValue(VWAPsellflag)  == LastValue(vzosellflag) == LastValue(SupTsellflag) ==0);
//Sell =   (LastValue(VWAPsellflag)==LastValue(vzosellflag)==LastValue(SupTsellflag)==1) AND (LastValue(VWAPbuyflag)  == LastValue(vzobuyflag) == LastValue(SupTbuyflag) ==0);

//sideways = ((LastValue(VWAPbuyflag)==LastValue(vzobuyflag)==LastValue(SupTbuyflag)==1) AND (LastValue(VWAPsellflag)  | LastValue(vzosellflag) | LastValue(SupTsellflag) ==1))
   //        OR    ((LastValue(VWAPsellflag)==LastValue(vzosellflag)==LastValue(SupTsellflag)==1) AND (LastValue(VWAPbuyflag)  | LastValue(vzobuyflag) | LastValue(SupTbuyflag) ==1))
      //     OR    ((LastValue(VWAPsellflag) | LastValue(vzosellflag) | LastValue(SupTsellflag)==1) AND (LastValue(VWAPbuyflag)  | LastValue(vzobuyflag) | LastValue(SupTbuyflag) ==1));
      

///////////////////////////////////////////////////////////////////////////////////////////////////////
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );
//Buy = Flip( Buy, Sell );
//Sell = Flip(Sell,Buy);
///////////////////////////////////////////////////////////////////////////////////////////////////////
PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorGreen, 0, L, Offset = -12 );
        PlotShapes( IIf( Sell, shapeDownArrow, shapeNone ), colorRed, 0, H, Offset = -12 );

AlertIf( Buy, "SOUND C:\\Program Files (x86)\\AmiBroker\\Sound Alerts\\alert1.wav", "Audio alert", 2 );
AlertIf( Sell, "SOUND C:\\Program Files (x86)\\AmiBroker\\Sound Alerts\\alert1.wav", "Audio alert", 2 );
Filter = Buy OR Sell;
    
//if(Candletype)
//{
//SetBarFillColor(  IIf ( (Sell) AND (!sideways),colorRed,colorBrightGreen));
//Plot(C,"Price",     IIf ( (Hlv == -1 &&  Hlv  !=1  &&  Hlv  !=0) AND NOT(Hlv == 1 &&  Hlv  !=-1  &&  Hlv  !=0),colorRed,colorBrightGreen),styleCandle);
//}
//else
//{
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
//}

_SECTION_END();
Above is my simple strategy. AFLs of the components are available on net and on Traderji.

I buy when Volume Zone Oscillator, VWAP and SuperTrend all are positively in Buy Mode. And do wait for reverse signals on all 3 to initiate a Short.

Tried to put all three conditions as a ribbon on my chart to remove all clutter. But i do not know how to "hold" a signal until reverse signal appears.

I have created a small Algorithm which if coded correctly can give desired results. Below, have a look.

===================================
**********************BEGIN*********************** ***
===================================


Initial Declare / Asssign values to flags
greenflagup = 0;
yellowflagup = 0;
redflagup =0;


if at end of most current bar ---> ((buy1 and buy2 and buy3) are all true) AND ((sell1 and sell2 and sell3) are all false);
greenflagup = 1;
(( ACTION -- color of all bars to remain GREEN from CURRENT BAR ONWARDS) uptill greenflagup = 1);


if at the end of current bar ---> (EITHER OF ( Sell1 or Sell2 or Sell3) are true (BUT NOT ALL TRUE TOGETHER, that is, (Sell1 and Sell2 and Sell3 ) != TRUE);
greenflagup = 0;
yellowflagup = 1;
(( ACTION -- color of all bars to remain GREY from CURRENT BAR ONWARDS) uptill yellowflagup = 1);


if at end of most current bar ---> ((Sell1 and Sell2 and Sell3 ) are all true) AND ((buy1 and buy2 and buy3) are all false);
redflagup = 1;
(( ACTION -- color of all bars to remain RED from CURRENT BAR ONWARDS) uptill REDflagup = 1);


if at the end of current bar ---> (EITHER OF ( buy1 OR buy2 OR buy3) are true (BUT NOT ALL TRUE TOGETHER, that is, ( buy1 AND buy2 AND buy3 ) != TRUE);
redflagup = 0;
yellowflagup = 1;
(( ACTION -- color of all bars to remain GREY from CURRENT BAR ONWARDS) uptill yellowflagup = 1);
 
Last edited:
#5
Would really appreciate even if given clues to the solution..

please help ..
Define all of your 3 Buy/Cover conditions separately

UP_01 = ....
UP_02 = ....
UP_03 = ....

and also all of your 3 Sell/Short conditions separately

DN_01 = ....
DN_02 = ....
DN_03 = ....


Then


Buy = UP_01 AND UP_02 AND UP_03; //all 3 +ve
Sell = DN_01 OR DN_02 OR DN_03; // any one -ve

Short = DN_01 AND DN_02 AND DN_03; //all 3 -ve
Cover = UP_01 OR UP_02 OR UP_03;// any one +ve

after that use ExRem to remove extra signals, and then plot arrows

Happy :)
 

radiosilk

Active Member
#6
Hi Happy,

Thanks for replying. May be i didn't understand your point. Still, please have a look at the code. Are you suggesting to check for ALL the 3 buy conditions at LATEST candle ? If yes, then that will not work. Because we are checking for 3 different buy conditions which could have become true on 3 different candles.

Please take this as example that a buy signal on VZO came 3 bars ago, super trend just turned green on this bar and price has still not crossed VWAP line so we are still waiting for our 3rd signal --- ie, price crossing the vwap line.

Say, that on next bar price crosses the vwap line. Then all our buy rules are now true and hence we place a buy order. This means that we are combining 3 different indicators in our rule to automate. This helps in reducing decision making load on mind during trading hours.

If i am not wrong, then yours is the suggestion that i tried the first time.

It's bad for non-developers that they can't combine signals of 2 or more indicators in 1 indicator alone.

Please, if you have any idea in mind, do share..
 
#7
Ok then use these steps . . .

BUY01 = ....
Sell01 = ....

UP_01 = Flip(Buy01,Sell01);
DN_01 = Flip(Sell01,Buy01);

do the same for all 3 conditions

after that, use the logic given above to combine signals . . .

Happy :)


Hi Happy,

Thanks for replying. May be i didn't understand your point. Still, please have a look at the code. Are you suggesting to check for ALL the 3 buy conditions at LATEST candle ? If yes, then that will not work. Because we are checking for 3 different buy conditions which could have become true on 3 different candles.

Please take this as example that a buy signal on VZO came 3 bars ago, super trend just turned green on this bar and price has still not crossed VWAP line so we are still waiting for our 3rd signal --- ie, price crossing the vwap line.

Say, that on next bar price crosses the vwap line. Then all our buy rules are now true and hence we place a buy order. This means that we are combining 3 different indicators in our rule to automate. This helps in reducing decision making load on mind during trading hours.

If i am not wrong, then yours is the suggestion that i tried the first time.

It's bad for non-developers that they can't combine signals of 2 or more indicators in 1 indicator alone.

Please, if you have any idea in mind, do share..
 

Abhi1284

Active Member
#8
Hi Happy,

Thanks for replying. May be i didn't understand your point. Still, please have a look at the code. Are you suggesting to check for ALL the 3 buy conditions at LATEST candle ? If yes, then that will not work. Because we are checking for 3 different buy conditions which could have become true on 3 different candles.

Please take this as example that a buy signal on VZO came 3 bars ago, super trend just turned green on this bar and price has still not crossed VWAP line so we are still waiting for our 3rd signal --- ie, price crossing the vwap line.

Say, that on next bar price crosses the vwap line. Then all our buy rules are now true and hence we place a buy order. This means that we are combining 3 different indicators in our rule to automate. This helps in reducing decision making load on mind during trading hours.

If i am not wrong, then yours is the suggestion that i tried the first time.

It's bad for non-developers that they can't combine signals of 2 or more indicators in 1 indicator alone.

Please, if you have any idea in mind, do share..

_SECTION_BEGIN( "Confluence" );
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////Volume Zone Oscillator/////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////


//Volume Zone Oscillator
C1=C;
V1=V;
period=Param("LookBack",14,2,999,1,0);
R= IIf (C1>Ref(C1,-1), V1,-V1);
VP= EMA (R, period);
TV=EMA (V, period);
VZO= 100*(VP/TV);
//Plot(VZO,"",colorOrange,4);
//Plot(60,"",colorPaleBlue,styleLine);
//Plot(40,"",colorPaleBlue,styleLine);
//Plot(0,"",colorDefault,styleDashed);
//Plot(-60,"",colorPaleBlue,styleLine);
//Plot(-40,"",colorPaleBlue,styleLine);
//PlotOHLC(Null,60,40,Null,"",colorDarkGreen);//Removed stylecloud
//PlotOHLC(Null,-60,-40,Null,"",colorDarkRed); //Removed styleCloud


///////////////////////////////buy/sell///////////////////////
//zerochkbuy = IIf(Cross(0,Ref(VZO,-1)) AND Cross(VZO,0),True,False);
//zerochksell = IIf(Cross(Ref(VZO,-1),0)AND Cross(0,VZO),True,False);

//Buy=Cross(VZO,-40) OR zerochkbuy;Sell=Cross(40,VZO) OR zerochksell ;
Buy1=Cross(VZO,-40) OR Cross(VZO,0);
Sell1=Cross(40,VZO) OR Cross(0,VZO);
//Buy = ExRem( Buy, Sell );
//Sell = ExRem( Sell, Buy );
/////////////////////////shapes ///////////////////////////////
//shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
//PlotShapes( shape, IIf( Buy, colorBrightGreen, colorRed ),0, IIf( Buy,VZO,VZO) );
/////////////////////////exploration ///////////////////////////////
//Filter=Buy OR Sell;
//AddColumn( IIf(Buy,1,IIf(Sell,-1,Null)) ,"B/S",1.0,colorWhite,IIf(Buy,colorGreen,IIf(Sell,colorRed,Null)),60);

///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////Volume Zone Oscillator/////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////



///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////SuperTrend ATR System///////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
Factor = Param( "Factor", 1, 1, 10, 0.1 );
Pd = Param( "ATR Periods", 5, 1, 100, 1 );

Up = ( H + L ) / 2 + ( Factor * ATR( Pd ) );
Dn = ( H + L ) / 2 - ( Factor * ATR( Pd ) );
iATR = ATR( Pd );
TrendUp = TrendDown = Null;
trend[0] = 1;
changeOfTrend = 0;
flag = flagh = 0;

for ( i = 1; i < BarCount - 1; i++ )
{
TrendUp = Null;
TrendDown = Null;

trend = 1;


if ( Close > Up[i-1] )
{
trend = 1;

if ( trend[i-1] == -1 )
changeOfTrend = 1;

}
else
if ( Close < Dn[i-1] )
{
trend = -1;

if ( trend[i-1] == 1 )
changeOfTrend = 1;
}
else
if ( trend[i-1] == 1 )
{
trend = 1;
changeOfTrend = 0;
}
else
if ( trend[i-1] == -1 )
{
trend = -1;
changeOfTrend = 0;
}

if ( trend < 0 && trend[i-1] > 0 )
{
flag = 1;
}
else
{
flag = 0;
}

if ( trend > 0 && trend[i-1] < 0 )
{
flagh = 1;
}
else
{
flagh = 0;
}

if ( trend > 0 && Dn < Dn[i-1] )
{
Dn = Dn[i-1];
}

if ( trend < 0 && Up > Up[i-1] )
{
Up = Up[i-1];
}

if ( flag == 1 )
{
Up = ( H + L ) / 2 + ( Factor * iATR );;
}

if ( flagh == 1 )
{
Dn = ( H + L ) / 2 - ( Factor * iATR );;
}

if ( trend == 1 )
{
TrendUp = Dn;

if ( changeOfTrend == 1 )
{
TrendUp[i-1] = TrendDown[i-1];
changeOfTrend = 0;
}
}
else
if ( trend == -1 )
{
TrendDown = Up;

if ( changeOfTrend == 1 )
{
TrendDown[i-1] = TrendUp[i-1];
changeOfTrend = 0;
}
}
}

// Plot( TrendUp, "Trend", colorBrightGreen , styleNoRescale);

// Plot( TrendDown, "Down", colorRed , styleNoRescale);




//////////////////////////////SuperTrend BUY CONDITIONS///////////////////////////////////////////////////////////
Buy2 = IIf(trend == 1,1,0);
//////////////////////////////SuperTrend SELL CONDITIONS////////////////////////////////////
Sell2 = IIf(trend == -1,1,0);
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////



///////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////VWAP CALCULATIONS////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////


starttime = 093000;
endtime = 160000;

timeWindow = TimeNum() >= starttime AND TimeNum() <= endtime;
firstBarOfDay = TimeNum() >= starttime ;
firstBarOfDay = firstBarOfDay - Ref(firstBarOfDay,-1);

P = (H + L)/2;

vv = V * P * timeWindow;

BarsInDay = (1 + BarsSince(firstBarOfDay)) * timeWindow;
CumVolumeInDay = Sum(V,BarsInDay);
VWAP = Sum(vv, BarsInDay ) / CumVolumeInDay;
SV = Sum((P - VWAP)^2,BarsInDay) / BarsInDay; // sample variance
SD = sqrt(SV); // standard deviation
period = ParamList( "What period?", "Daily|Weekly|Monthly", 0 );

switch ( period )
{

case "Daily":
newPeriod = Day() != Ref( Day(), -1 );
break;

case "Weekly":
newPeriod = DayOfWeek() == 0 AND Ref( DayOfWeek(), -1 ) != 0;
break;

case "Monthly":
newPeriod = Month() != Ref( Month(), -1 );
break;
}
//////////////////////////////VWAP BUY CONDITIONS///////////////////////////////////////////////////////////
Buy3 = Ref(C,-1) > VWAP ;
//////////////////////////////VWAP SELL CONDITIONS///////////////////////////////////////////////////////////
Sell3 = Ref(C,-1) < VWAP ;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////Buy Sell Logic///////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
Buy = Buy1 AND Buy2 AND Buy3;
Sell = Sell1 AND Sell2 AND Sell3;


Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );
//Buy = Flip( Buy, Sell );
//Sell = Flip(Sell,Buy);
///////////////////////////////////////////////////////////////////////////////////////////////////////
PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorGreen, 0, L, Offset = -12 );
PlotShapes( IIf( Sell, shapeDownArrow, shapeNone ), colorRed, 0, H, Offset = -12 );

AlertIf( Buy, "SOUND C:\\Program Files (x86)\\AmiBroker\\Sound Alerts\\alert1.wav", "Audio alert", 2 );
AlertIf( Sell, "SOUND C:\\Program Files (x86)\\AmiBroker\\Sound Alerts\\alert1.wav", "Audio alert", 2 );
Filter = Buy OR Sell;

//if(Candletype)
//{
//SetBarFillColor( IIf ( (Sell) AND (!sideways),colorRed,colorBrightGreen));
//Plot(C,"Price", IIf ( (Hlv == -1 && Hlv !=1 && Hlv !=0) AND NOT(Hlv == 1 && Hlv !=-1 && Hlv !=0),colorRed,colorBrightGreen),styleCandle);
//}
//else
//{
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
//}

_SECTION_END();


chk this
 

radiosilk

Active Member
#9
Ok then use these steps . . .

BUY01 = ....
Sell01 = ....

UP_01 = Flip(Buy01,Sell01);
DN_01 = Flip(Sell01,Buy01);

do the same for all 3 conditions

after that, use the logic given above to combine signals . . .

Happy :)
Oh yes, i have not tried flip with individual conditions. Will give that a shot tomorrow in the morning and will report back..
 
#10
PHP:
Buy =   Buy1 AND Buy2 AND Buy3;
Sell =   Sell1 AND Sell2 AND Sell3;
chk this
Hi Abhishek, Correct me if i am wrong. It seems that you made change to the buy sell statements like below:
Buy = Buy1 AND Buy2 AND Buy3;
Sell = Sell1 AND Sell2 AND Sell3;

But that might not fit the purpose.

Shall check Happy's suggested solution tomorrow in the morning and will report back..
 

Similar threads