Quantcast
Amibroker - how to identify a week of falling close prices? - Aussie Stock Forums

Results 1 to 5 of 5
  1. #1

    Default Amibroker - how to identify a week of falling close prices?

    Hi All,

    I try to create a stop loss - if XAO records three consecutive weeks of falling prices (XAO on Friday < XAO on Monday for the last three weeks), then I want to stop trading until there is at least one week of raising prices. I don't know if this will give good results, but at least I want to learn how to do it and run some simulations.

    Thanks,
    Nick

  2. #2

    Default Re: Amibroker - how to identify a week of falling close prices?

    Try this. Not exactly what you want but worth a look. Close is based on end of week close.

    Code:
    SetOption("InitialEquity", 100000);
    PosQty = 4; 
    SetOption("MaxOpenPositions", PosQty );
    PositionSize = -100/PosQty; 
    SetOption ("UsePrevBarEquityForPosSizing", True);
    PositionScore = MACD() > 0;
    SetTradeDelays(1, 1, 1, 1);
    
    TurnOver = MA(C*V, 50) > 250000; 
    
    //// Index close is 3 consecutive weeks lower \\\\
    
    SetForeign("^AORD");
    ThisWeek = TimeFrameGetPrice("C", inWeekly, 0); 
    LastWeek = TimeFrameGetPrice("C", inWeekly, -1);
    TwoWeeksAgo = TimeFrameGetPrice("C", inWeekly, -2);
    IndexDownWeekly = ThisWeek < LastWeek & LastWeek < TwoWeeksAgo;
    RestorePriceArrays(); 
    
    
    Buy =  C >= HHV(C, 26) & TurnOver; // Buy if a stock price closes above the 26 bar highest closing price 
    Sell = IndexDownWeekly; // Sell if All Ordinaries Index weekly close is less 3 times consecutively

  3. #3

    Default Re: Amibroker - how to identify a week of falling close prices?

    OK, here is the one that should come close in regards to counting consecutive weeks with falling prices.

    Code:
    // three consecutive weeks of falling prices
    // for NickF at aussiestockforums.com, 2014
    // http://www.aussiestockforums.com/forums/newreply.php?do=postreply&t=28392
    
    dow = DayOfWeek();
    Fri = dow == 5;
    Mon = dow == 1;
    FriC = Valuewhen( Fri, C );
    MonC = Valuewhen( Mon, C );
    Cond = FriC < MonC AND Fri;
    
    friday = Null;
    myvar = Null;
    count = 3;
    n = 0;
     
    for ( i = 1; i < BarCount; i++ )
    {
        if ( Fri[i] )
        { 
            friday[n] = Cond[i];
            n++;
        } 
     
        if  ( n > count /*&& Fri[i]*/ )
        {
            cumfridays = 0;
     
            for ( j = n - count; j < n; j++ )
            {           
                cumfridays += friday[j];
            }
            myvar[i] = cumfridays;
        }
    }
    
    // Plotting :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    function PlotOwnScale( input, chartName, color, minPerc, maxPerc )
    {// function by Marcin G.
        minVal = LowestVisibleValue( input );
        maxVal = HighestVisibleValue( input );
    
        onePerc = ( maxVal - minVal ) / ( maxPerc - minPerc );
        minScale = minVal - minPerc * onePerc;
        maxScale = maxVal + ( 100 - maxPerc ) * onePerc;
    
        Plot( input, chartName, color, styleHistogram | styleOwnScale, minScale, maxScale, 0, 0, -50 );
    }
    
    PlotOwnScale( myvar, "Sum", colorbrightgreen, 0, 40 );
    PlotOwnScale( Cond, "Single Occurrence", colorRed, 40, 80 );

  4. #4

    Default Re: Amibroker - how to identify a week of falling close prices?

    Just a small follow up to extract only the required info

    Code:
    // three consecutive weeks of falling prices
    // for NickF at aussiestockforums.com, 2014
    // http://www.aussiestockforums.com/forums/newreply.php?do=postreply&t=28392
    
    dow = DayOfWeek();
    Fri = dow == 5;
    Mon = dow == 1;
    FriC = Valuewhen( Fri, C );
    MonC = Valuewhen( Mon, C );
    Cond = FriC < MonC AND Fri;
    
    count = 3; // number of consecutive occurrences
    
    friday = Null;
    myvar = Null;
    n = 0;
     
    for ( i = 1 ; i < BarCount ; i ++ )
    {
        if ( Fri[i] )
        { 
            friday[n] = Cond[i];
            n++;
        } 
     
        if  ( n > count && Fri[i] )
        {
            cumfridays = 0;
     
            for ( j = n - count; j < n; j++ )
            {           
                cumfridays += friday[j];
            }        
    
            myvar[i] = cumfridays;
        }
    }
    
    myvar =  iif( myvar == count, myvar, 0 );
    
    // Plotting :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    procedure PlotOwnScale( input, chartName, color, minPerc, maxPerc )
    {// function by Marcin G.
        minVal = LowestVisibleValue( input );
        maxVal = HighestVisibleValue( input );
    
        onePerc = ( maxVal - minVal ) / ( maxPerc - minPerc );
        minScale = minVal - minPerc * onePerc;
        maxScale = maxVal + ( 100 - maxPerc ) * onePerc;
    
        Plot( input, chartName, color, styleHistogram | styleOwnScale, minScale, maxScale, 0, 0, -50 );
    }
    
    PlotOwnScale( Cond, "Single Occurrence", colorRed, 40, 80 );
    PlotOwnScale( myvar, "Sum", colorbrightgreen, 0, 40 );

  5. #5

    Default Re: Amibroker - how to identify a week of falling close prices?

    Thank you so much, Trash. I will try using the code you kindly provided.

    Nick

    Quote Originally Posted by trash View Post
    Just a small follow up to extract only the required info

    Code:
    // three consecutive weeks of falling prices
    // for NickF at aussiestockforums.com, 2014
    // http://www.aussiestockforums.com/forums/newreply.php?do=postreply&t=28392
    
    dow = DayOfWeek();
    Fri = dow == 5;
    Mon = dow == 1;
    FriC = Valuewhen( Fri, C );
    MonC = Valuewhen( Mon, C );
    Cond = FriC < MonC AND Fri;
    
    count = 3; // number of consecutive occurrences
    
    friday = Null;
    myvar = Null;
    n = 0;
     
    for ( i = 1 ; i < BarCount ; i ++ )
    {
        if ( Fri[i] )
        { 
            friday[n] = Cond[i];
            n++;
        } 
     
        if  ( n > count && Fri[i] )
        {
            cumfridays = 0;
     
            for ( j = n - count; j < n; j++ )
            {           
                cumfridays += friday[j];
            }        
    
            myvar[i] = cumfridays;
        }
    }
    
    myvar =  iif( myvar == count, myvar, 0 );
    
    // Plotting :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    procedure PlotOwnScale( input, chartName, color, minPerc, maxPerc )
    {// function by Marcin G.
        minVal = LowestVisibleValue( input );
        maxVal = HighestVisibleValue( input );
    
        onePerc = ( maxVal - minVal ) / ( maxPerc - minPerc );
        minScale = minVal - minPerc * onePerc;
        maxScale = maxVal + ( 100 - maxPerc ) * onePerc;
    
        Plot( input, chartName, color, styleHistogram | styleOwnScale, minScale, maxScale, 0, 0, -50 );
    }
    
    PlotOwnScale( Cond, "Single Occurrence", colorRed, 40, 80 );
    PlotOwnScale( myvar, "Sum", colorbrightgreen, 0, 40 );



Similar Threads

  1. AmiBroker: How to draw in blank bars in the right margin?
    By atlas in forum Software and Data
    Replies: 8
    Last Post: 6th-February-2012, 03:19 PM
  2. Replies: 0
    Last Post: 31st-August-2011, 11:58 PM
  3. How much money per week do you need to live on?
    By Bill M in forum General Chat
    Replies: 76
    Last Post: 17th-April-2011, 03:10 PM
  4. Amibroker - How to do this?
    By R0n1n in forum Software and Data
    Replies: 7
    Last Post: 11th-September-2009, 02:01 PM
  5. How far can a spec stock fall?
    By Pommiegranite in forum ASX Stock Chat
    Replies: 29
    Last Post: 17th-August-2007, 02:30 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Aussie Stock Forums