Amibroker Exploration program

Discussion in 'App Development' started by ben.lai, Sep 22, 2014.

  1. ben.lai

    ben.lai

    I want to explore by RSI(14) first,

    if RSI(14) is bullish or berish, then show both MA45 and MA 100 too
    else if RSI(14) is neutral, the stocks are not shown on the exploration result

    How to change the program?

    Also, for the function of SetSortColumns,

    can i sort the stocks by column(3) first
    then the left rows are sorted by column(5)?


    Many Thanks!!!

    i=0;
    //52 Week High Low
    High52 = HHV(High,250);
    Low52 = LLV(Low,250);

    //RSI
    R1=RSI(14)>30 AND Ref(RSI(14),-1)<30 AND Ref(RSI(14),-2)<30;
    R2=RSI(14)<70 AND Ref(RSI(14),-1)>70 AND Ref(RSI(14),-2)>70;
    IIf(R1,i+1,i);
    RSIStatus=WriteIf(R1,"Improving",WriteIf(R2,"Decli ning",WriteIf(IsNull(RSI(14)),"N/A","Neutral")));
    RSIColor=IIf(R1,colorGreen,IIf(R2,colorRed,colorLightGrey));

    //Moving Average (Short, Mid & Long Term)
    MAMid = C>MA(C,45);
    IIf(MAMid,i+1,i);
    MALong = C>MA(C,100);
    IIf(MALong,i+1,i);
    MidStatus = WriteIf(MAMid,"Bullish",WriteIf(IsNull(MA(C,45))," N/A","Bearish"));
    MidColor = IIf(MAMid,colorGreen,colorRed);
    LongStatus = WriteIf(MALong,"Bullish",WriteIf(IsNull(MA(C,100)) ,"N/A","Bearish"));
    LongColor = IIf(MALong,colorGreen,colorRed);

    Filter = 1;

    AddColumn(C,"Close",1,IIf(C>Ref(C,-1),colorGreen,colorRed));
    AddColumn(V,"Volume",1,IIf(V>Ref(V,-1),colorGreen,colorRed));

    AddTextColumn(RSIStatus,"RSI(14)",1,colorWhite,RSIColor);
    AddTextColumn(MidStatus,"Mid MA(45)",1,colorWhite,MidColor);
    AddTextColumn(LongStatus,"Long MA(100)",1,colorWhite,LongColor);
     
  2. ST.M

    ST.M

    Iif is an array function. So writing this

    IIf(MAMid,i+1,i);

    is incorrect. Look at their help http://www.amibroker.com/guide/a_mistakes.html

    Correct is this one

    myvar = IIf(MAMid,i+1,i);

    Since i is 0 it means

    myvar = IIf(MAMid,1,0); or

    myvar = IIf(MAMid,true,false);

    Both ways are not required as MAMid is a condition returning true or false already so it is things done twice.
    Therefore following is enough.

    myvar = MAMid;

    Which means you can just use MAMid.

    Filter = 1; means Filter = True;
    So output all there is.

    Since you wanna Filter by RSI condition and just most recent occurrence your filter just needs further specification like
    Filter = ( R1 OR R2 ) AND Status( "lastbarinrange" );


    Code:
    //RSI
    myRSI = RSI( 14 );
    R1 = myRSI > 30 AND Ref( Sum( myRSI < 30, 2 ) == 2, -1 );
    R2 = myRSI < 70 AND Ref( Sum( myRSI > 70, 2 ) == 2, -1 );
    
    RSIStatus = WriteIf( R1, "Improving", 
                WriteIf( R2, "Declining", 
                WriteIf( IsNull( myRSI ), "N/A", 
                "Neutral" ) ) );
                
    RSIColor = IIf( R1, colorGreen, 
               IIf( R2, colorRed, 
               colorLightGrey ) );
               
    
    //Moving Average (Short, Mid & Long Term)
    myMA1 = MA( C, 45 );
    myMA2 = MA( C, 100 );
    MAMid = C > myMA1;
    MALong = C > myMA2;
    
    MidStatus = WriteIf( MAMid, "Bullish", 
                WriteIf( IsNull( myMA1 ), "N/A", 
                "Bearish" ) );
    MidColor = IIf( MAMid, colorGreen, colorRed );
    
    LongStatus = WriteIf( MALong, "Bullish", 
                 WriteIf( IsNull( myMA2 ) , "N/A", 
                 "Bearish" ) );
    LongColor = IIf( MALong, colorGreen, colorRed );
    
    
    // filter by RSi conditions and output only most recent occurrence
    Filter = ( R1 OR R2 ) AND Status( "lastbarinrange" ); 
    
    SetSortColumns( 5, -7 );
    
    AddColumn( C, "Close", 1.2, IIf( ROC( C, 1 ) > 0, colorGreen, colorRed ), colorDefault, 80 );
    AddColumn( V, "Volume", 1, IIf( ROC( V, 1 ) > 0, colorGreen, colorRed ), colorDefault, 80 );
    
    AddTextColumn( RSIStatus, "RSI(14)", 1, colorWhite, RSIColor, 110 );
    AddTextColumn( MidStatus, "Mid MA(45)", 1, colorWhite, MidColor, 110 );
    AddTextColumn( LongStatus, "Long MA(100)", 1, colorWhite, LongColor, 110 );
     
  3. ben.lai

    ben.lai

    Oh.....Many Thanks for your kindly help!!!