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

[amibroker] SellPrice Based on BuyPrice



PureBytes Links

Trading Reference Links

In AFL,
because Buy is 'True' on 'Buy' signals after entry
a 'SellPrice' based on: ValueWhen(Buy, BuyPrice);
may not be based on the actual entry price.

I read,
that for a correct entry price
using a loop is necessary.

I have modified a loop I found,
[modified loops shown below],
and in Exploration
the stop shown is correct on the entry day.
However, as in AFL the stop changes 
with each new buy signal.

I have tried two variations 
of the location of the Array Subscript Operator.

Could someone correct one of these loops
to produce the actual BuyPrice plus or minus a fixed amount?

Thank you,
DirectAim


//===XIT================================================
ATRDy=  ATR(14);
CrshStpMult= 1;
TargMult= 1;

//XIT LOOP 1 FOR LNGS===================================
BuyPrice= C;
Sell= 0;
TargLvlLng=    0;
CrshStpLvlLng= 0;
TargLvlLngARRAY=    Null;
CrshStpLvlLngARRAY= Null;

//XIT LOOP FOR LNGS
for(i=1; i<BarCount; i++)
{
if(TargLvlLng== 0 AND CrshStpLvlLng== 0 AND Buy[i]) 
  {TargLvlLng=    BuyPrice[i]+    TargMult* ATRDy[i];
   CrshStpLvlLng= BuyPrice[i]- CrshStpMult* ATRDy[i];}

else Buy[i]= 0;  //REMOV XCESS BUY SIGS 

if( TargLvlLng> 0 AND H[i]> TargLvlLng)
  {Sell[i]= 1;
   SellPrice[i]= TargLvlLng;
   TargLvlLngARRAY[i]= TargLvlLngARRAY[i];
   TargLvlLng=0;
   CrshStpLvlLng=0;}

if(CrshStpLvlLng> 0 AND L[i]< CrshStpLvlLng)
  {Sell[i]= 1;
   SellPrice[i]= CrshStpLvlLng;
   CrshStpLvlLngARRAY[i]= CrshStpLvlLng;
   CrshStpLvlLng= 0;
   TargLvlLng= 0;}

//REAJUST TargLvlLng + CrshStpLvlLng ON EA BAR?
if(TargLvlLng> 0)
  {TargLvlLng= BuyPrice[i]+ TargMult* ATRDy[i];
   TargLvlLngARRAY[i]= TargLvlLng;}

if(CrshStpLvlLng> 0)
  {CrshStpLvlLng= BuyPrice[i]- CrshStpMult* ATRDy[i];
   CrshStpLvlLngARRAY[i]= CrshStpLvlLng;}
}


//XIT LOOP 2 FOR LNGS===================================
for(i=1; i<BarCount; i++)
{
if(TargLvlLng== 0 AND CrshStpLvlLng== 0 AND Buy[i] ) 
  {TargLvlLng=    BuyPrice+ TargMult*    ATRDy;
   CrshStpLvlLng= BuyPrice- CrshStpMult* ATRDy;}

else Buy[i]= 0;  //REMOV XCESS BUY SIGS 

if( TargLvlLng[i]> 0 AND H[i]> TargLvlLng[i])
  {Sell[i]= 1;
   SellPrice[i]= TargLvlLng[i];
   TargLvlLngARRAY[i]= TargLvlLngARRAY[i];
   TargLvlLng=0;
   CrshStpLvlLng=0;}

if(CrshStpLvlLng[i]> 0 AND L[i]< CrshStpLvlLng[i])
  {Sell[i]= 1;
   SellPrice[i]= CrshStpLvlLng[i];
   CrshStpLvlLngARRAY[i]= CrshStpLvlLng[i];
   CrshStpLvlLng= 0;
   TargLvlLng= 0;}

//REAJUST TargLvlLng + CrshStpLvlLngON EA BAR?
if(TargLvlLng[i]> 0)
  {TargLvlLng= BuyPrice[i]+ TargMult* ATRDy[i];
   TargLvlLngARRAY[i]= TargLvlLng;}

if(CrshStpLvlLng[i]> 0)
  {CrshStpLvlLng= BuyPrice[i]- CrshStpMult* ATRDy[i];
   CrshStpLvlLngARRAY[i]= CrshStpLvlLng;}
}


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

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

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

For other support material please check also:
http://www.amibroker.com/support.html
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/