[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Jurik RSX Entry/Exit for auto-trade with trailing stop



PureBytes Links

Trading Reference Links

Not sure if this will work, and there are no error messages in the
chart strip for this indicator.  Basically, long entry/exits are based
on the Jurik RSX indicator going up or down, respectively.  

When RSX starts to go up, I want to transmit a long buy order for 100
shres, and when RSX starts to go down I want to initiate a sell order. 

However, for the buy order, I also want to immediately follow with a
GTC trailing stop (sell) order based on 3% of the last close when the
buy order was made. 

Please let me know if you think this will work.  The parameters at the
beginning were borrowed from the Jurik RSX indicator graph commands. 
Thx - LP 

// ----- Chart Parameters ---------------

StopLevel = Param("Trailing stop %", 3, 0.1, 10, 0.1)/100;

series    = ParamField("Series", 4);
len       = Param( "RSX length", 20, 2, 200, 1, 10 );
topLine   = Param( "Upper Threshold Line", 80, -1, 101, 1, 0 );
botLine   = Param( "Lower Threshold line", 20, -1, 101, 1, 0 );

style     = ParamStyle( "Style", styleThick);
fill_Flag = ParamToggle( "Solid Color Fill?", "No|Yes", 1);
dyna_Flag = ParamToggle( "Dynamic Color Change?", "No|Yes", 1);
label     = ParamStr( "label text", "RSX" );

UPcolor   = ParamColor( "Long Color", ColorRGB(0,255,0)); 
DNcolor   = ParamColor( "Short Color", colorRed); 
NOcolor   = ParamColor( "Null Color", ColorRGB(219,219,219)); 

// ----- Analysis -----------------------

SetBarsRequired(ceil(3.5 * Len)) ;   // minimum lookback required for
stability //
RSXarray 	= JurikRSX(series, len);


Buy = RSXarray > botline AND (RSXarray > Ref(RSXarray,-1) OR RSXarray
> 99);

Sell = RSXarray < topline AND (RSXarray < Ref(RSXarray,-1) OR RSXarray
< 1);


if( LastValue( Buy ) )
{
   ibc = GetTradingInterface("IB");

   // check if we are connected OK
   if( ibc.IsConnected() )
    {
       // place orders only if we do not have already open position on
this symbol
      if( ibc.GetPositionSize( Name() ) == 0 )
       {
         // retrieve orderID from previous run, will be empty if no
order was placed before  
          OrderID = StaticVarGetText("OrderID"+Name());
      
          // place or modify the order - don't transmit yet
          OrderID = ibc.ModifyOrder( OrderID, Name(), "BUY",
100,"MKT", 0, 0, "Day", True );
          ibc.PlaceOrder( Name(), "Sell", 100, "TRAIL", 0, LastValue(
C ) * StopLevel, "GTC", True );           
         // store orderID for next run so we know which order to modify
         StaticVarSetText("OrderID"+Name(), OrderID);
       }
    }
} 


if( LastValue( Sell ) )
{
   ibc = GetTradingInterface("IB");

   // check if we are connected OK
   if( ibc.IsConnected() )
    {
       // place orders only if we do not have already open position on
this symbol
      if( ibc.GetPositionSize( Name() ) == 0 )
       {
         // retrieve orderID from previous run, will be empty if no
order was placed before  
          OrderID = StaticVarGetText("OrderID"+Name());
      
          // place or modify the order - don't transmit yet
          OrderID = ibc.ModifyOrder( OrderID, Name(), "Sell",
100,"MKT", 0, 0, "Day", True );
         // store orderID for next run so we know which order to modify
         StaticVarSetText("OrderID"+Name(), OrderID);
       }
    }
} 



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

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/