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

[amibroker] How can work on day bar with buyprice and shortprice?



PureBytes Links

Trading Reference Links

Hi,
I want to buy and short on the same day bar. I wrote simple afl,
AA->Explore working OK and I have buyprice and shortprice. But when I
run Scan or Backtest only one price from this day is ok.

Could anybody help me with my afl?

Regards

---

SetBarsRequired(100000,100000); // require all past and all future bars
SetOption("InitialEquity", 10000 );
SetOption("MaxOpenPositions", 100 );
SetTradeDelays(0,0,0,0);
SetOption("CommissionMode", 3);
SetOption("CommissionAmount", 10);
SetOption("FuturesMode", False);
SetOption("ReverseSignalForcesExit", True);
SetOption("AllowPositionShrinking", True);
SetOption("AccountMargin", 100);
SetOption("UsePrevBarEquityForPosSizing", False);
SetPositionSize(1, spsShares);
//SetPositionSize(35, spsPercentOfEquity);
RoundLotSize=1;
MarginDeposit=2500;
TickSize=1;
PointValue=10;

Buy = Sell = Cover = Short = 0;
BuyPrice = SellPrice = CoverPrice = ShortPrice = 0;
Profit = 0;

mnoznik = 0.3; //30%

// ##################
LastBuy = False;
LastShort = False;
for( i = 1; i < BarCount; i++ )
{
     Changed = False;    //one bar = max one signal
     if (!Changed) {
         if (High[i] >= High[i-1] +
ceil(mnoznik*abs(Close[i-1]-Open[i-i]))) {
             // now long position
             Changed = True;
             Buy[i] = True;
             Short[i] = True;
             BuyPrice[i]=High[i-1] +
ceil(mnoznik*abs(Close[i-1]-Open[i-1]));
             ShortPrice[i]=Close[i];
             Profit[i] = ShortPrice[i] - BuyPrice[i];
         }
     }
     if (!Changed) {
         if (Low[i] <= Low[i-1] -
ceil(mnoznik*abs(Close[i-1]-Open[i-1]))) {
             // now short position
             Changed = True;
             Short[i] = True;
             Buy[i] = True;
             ShortPrice[i]=Low[i-1] -
ceil(mnoznik*abs(Close[i-1]-Open[i-1]));
             BuyPrice[i]=Close[i];
             Profit[i] = ShortPrice[i] - BuyPrice[i];
         }
     }
}

Filter = ((BuyPrice > 0) || (ShortPrice > 0));
AddColumn(BuyPrice, "BuyPrice", format=1.0);
AddColumn(CoverPrice, "CoverPrice", format=1.0);
AddColumn(ShortPrice, "ShortPrice", format=1.0);
AddColumn(SellPrice, "SellPrice", format=1.0);
AddColumn(Profit, "Profit", format=1.0);



GraphXSpace = 10;
SetChartOptions(0,chartShowArrows|chartShowDates);

_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g,
Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H,
L, C, SelectedValue( ROC( C, 1 )) ));
_N(Title = Title + EncodeColor(colorRed));
_N(Title = Title + "\n" + "eL =" + "BuyPrice:" + BuyPrice + "
CoverPrice:" +  CoverPrice);
_N(Title = Title + "\n" + "eS =" + "ShortPrice: " + ShortPrice + "
SellPrice:" + SellPrice);
_N(Title = Title + "\n" + "Profit: " + Profit);


Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle |
ParamStyle("Style") | GetPriceStyle() );
PlotShapes(Buy*shapeUpArrow,colorGreen,0,Low);
PlotShapes(Short*shapeDownArrow, colorRed, 0, High);
PlotShapes(Sell*shapeHollowDownArrow,colorGreen,0,High +12);
PlotShapes(Cover*shapeHollowUpArrow, colorRed, 0, Low -12);




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/