Amibroker - Need help to plot candlestick spread chart

Discussion in 'Trading Software' started by HammockTrader, Nov 15, 2011.

  1. Good Day,

    I have the following code for an indicator that will plot the price difference between 2 securities using the close data. (In this case it is the spread between SLB and HAL)


    _SECTION_BEGIN("slb");
    spread = Foreign( "slb", "c") - Foreign( "hal", "c");
    Plot( spread, "spread", colorRed, styleCandle);
    _SECTION_END();


    Can someone please show me how to plot this as a candlestick chart using the open,high,low,close data? (keeping it as an indicator)


    thanks!
     
  2. Code:
    Name0   = Name();
    
    Ticker1 = ParamStr("Symbol 1", Name0 );
    Ticker2 = ParamStr("Symbol 2", Name0 );
    
    SetForeign(Ticker1);
    Open1   = O; 
    High1   = H; 
    Low1    = L; 
    Close1  = C; 
    RestorePriceArrays();
    
    SetForeign(Ticker2);
    Open2   = O; 
    High2   = H; 
    Low2    = L; 
    Close2  = C; 
    RestorePriceArrays();
    
    SpreadO = Open1/Open2;
    SpreadH = High1/High2;
    SpreadL = Low1/Low2;
    SpreadC = Close1/Close2;
    
    PlotOHLC( 1.0*SpreadO, 1.0* SpreadH , 1.0* SpreadL, 1.0* SpreadC, "Spread - Ratio", ParamColor("Color", colorRed), styleCandle ); 
    
     
  3. Thanks! Much appreciated.

    The code you posted is for a spread ratio chart, for those who are interested the following is for the spread difference chart.

    (open - close ,etc. instead of open/close)

    -------------------------------------------------

    Name0 = Name();

    Ticker1 = ParamStr("Symbol 1", Name0 );
    Ticker2 = ParamStr("Symbol 2", Name0 );

    SetForeign(Ticker1);
    Open1 = O;
    High1 = H;
    Low1 = L;
    Close1 = C;
    RestorePriceArrays();

    SetForeign(Ticker2);
    Open2 = O;
    High2 = H;
    Low2 = L;
    Close2 = C;
    RestorePriceArrays();

    SpreadO = Open1 - Open2;
    SpreadH = High1 - High2;
    SpreadL = Low1 - Low2;
    SpreadC = Close1 - Close2;

    PlotOHLC( 1.0*SpreadO, 1.0* SpreadH , 1.0* SpreadL, 1.0* SpreadC, "Spread - Ratio", ParamColor("Color", colorRed), styleCandle );
     
  4. You guys since you seem to knwo this program do you also know if There is a function available that does MC simulation using teh backtest output?
     
  5. drm7

    drm7

    Just FYI, just subtracting the OHLC1 from OHLC2 won't produce accurate highs or lows for the spread. First of all, the high of the spread is probably mathematically closer to (but not equal to) H1-L1, since "high" actually means "max spread value." Also, the two instruments don't necessarily make their highs and lows at the same time. Of course, the open and close of the spread should still be accurate.

    The only true way to generate an accurate OHLC candle of the spread is to match the two series tick for tick, then take the max spread for the high and min spread for the low. Also, for less liquid instruments, the ticks may not line up, as the bid-ask of one series may have drifted away from the last traded tick of another.

    Exchange-traded futures spreads (calendars and some butterflys) have their own price series with accurate OHLC values. Stocks and intermarket futures spreads are more problematic - as described above.

    EDIT: This holds for ratio spreads as well as difference spreads
     
  6. I know that. Did want to write the same in my replying post but was to tired. So thanks for stepping in
     
  7. Thanks drm7 for the clarification although it's not yet totally clear.

    I'm wanting to pair trade NYSE stocks intraday. My plan is to backfill the symbols and then collect ticks from my dde source (good quality dde).

    Do you think this will be fairly accurate or way out?

    (I'll have mental stops around $1.00 for most of my trades on fairly low priced spreads...)
     
  8. Yes it is
     
  9. has anyone ever come up with a way to fudge building spread candles from daily data points? i am currently working on this and having limited success. no surprise but i would be happy with something that approximates the volatility of daily candles.
     
  10. funnyguy

    funnyguy

    Spread candles of what? Spread between two tickers?
     
    #10     Feb 18, 2012