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

Re: [amibroker] Re: Multiple Stock charts...



PureBytes Links

Trading Reference Links

Hi Gpzany,

The script is mine.   To run it on multiple symbols you simply 'scan' every XX period via Automatic Analysis.  To restrict the stocks to the Final Universe, you keep them in a watchlist.  From memory, the script points to watchlist (1).

However, as I have stated repeatedly, if you are not 100% clear on what the formula does, please don't run it.  Auto-trading on a script you are not clear on is a fast way to lose money.

Regards,

Mark

On 7/24/07, gpzany13 <gpzany13@xxxxxxxxx> wrote:

Hello Tomasz,

Thanks for the reply...

You are correct. I am no expert or a programmer... the script was
posted freely on a forum by a generous chap for others to use, and I
have had alot of trouble working out the right way to run the script
on multiple symbols in real time simultaneously.

Here is the script:

=====================================================================

SetBarsRequired(100000,100000);
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g,
Lo %g, Close %g (%.1f%%)\n {{VALUES}}", O, H, L, C, SelectedValue(
ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle |
ParamStyle("Style") | GetPriceStyle() );

TimeFrameSet(inDaily);
DU1 = EMA(V,30) - 3 * EMA(V,5) > 0 AND EMA(V,5) > 0;
DU2 = EMA(V,30) > 2 * Ref(EMA(V,3),-6) AND EMA(V,30) > 2 * EMA(V,3)
AND Ref(EMA(V,3),-3) - EMA(V,3) > 0;
DU3 = EMA(V,30) > 2 * Ref(EMA(V,6),-3) AND EMA(V,30) > 2 * EMA(V,3)
AND Ref(EMA(V,6),-3) - EMA(V,3) > 0;
DU4 = V < 0.5* EMA(V,65);

//Dry Up Calculations
LowV = LLV(V,21);
MDU1 = ValueWhen(Month()!=Ref(Month(),-1),Ref(LowV,-1),1);
MDU2 = ValueWhen(Month()!=Ref(Month(),-1),Ref(LowV,-1),2);
MDU3 = ValueWhen(Month()!=Ref(Month(),-1),Ref(LowV,-1),3);
AvgDU = (MDU1 + MDU2 + MDU3)/3;
"AvgDU = " + AvgDU;
DUBand = AvgDU * (4986/10000);
"DUBand = " + DUBand;
DU5 = V < AvgDU + DUBand;
LBDU = AvgDU - DUBand;
"LBDU = " + LBDU;
FRV = 3 * AvgDU;
FRV1 = EMA(V,5) - EMA(V,30) > 100000;
"FRV1 = " + WriteVal(EMA(V,5) - EMA(V,30),1) + " > 100,000";
EMAV65 = EMA(V,65);
DV=V;
DryUp = (du1 OR DU2 OR DU3 OR DU4 OR du5);
TimeFrameRestore();
IDU1 = TimeFrameExpand(DU1,inDaily,expandFirst);
IDU2 = TimeFrameExpand(DU2,inDaily,expandFirst);
IDU3 = TimeFrameExpand(DU3,inDaily,expandFirst);
IDU4 = TimeFrameExpand(DU4,inDaily,expandFirst);
IDU5 = TimeFrameExpand(DU5,inDaily,expandFirst);
DailyEMAV65 = TimeFrameExpand(EMAV65,inDaily,expandFirst);
DayVol = TimeFrameExpand(DV,inDaily,expandFirst);
InDryUp = TimeFrameExpand(DryUp,inDaily,expandFirst);
DryUpSignal = TimeFrameExpand(Ref(DryUp,-1),inDaily,expandFirst);
PrevLBDU = TimeFrameExpand(Ref(LBDU,-1),inDaily,expandFirst);
DryUpVolume = TimeFrameExpand(AvgDU,inDaily,expandFirst);
FRV = 3 * DryUpVolume * 0.95;
PeakV = (6 * DryUpVolume);

//Exit conditions:
//Gainers Over Yesterday Between 5% AND 10% Inc.
//((C - C1) / C1) * 100 > 5 AND ((C - C1) / C1) * 100 < 10
//Gainers Over Yesterday Greater than 10%
//((C - C1) / C1) * 100 > 10

//Stage 1 OR Stage 3
//(H30 < 1.1 * L5) AND (H5 < 1.1 * L30)

//Stage 2 OR Stage 4
//((MAXC126 - MINC126) / MINC126) * 100

//Gappers
//L > H1 OR H < L1 AND V > 1000 OR (C * V) > 2500

//- - - - - - - - - - - - - - /- - - - - - - - - - - - - - /- - - - -
- - - - - - - - - /- - - - - - - - - - - - - -

Scan = Status("action") == 3; //Tests whether formula is being used
for a scan
IDStochThreshold = Param("Intraday Stochastic Threshold",80,1,100,1);
IDMACDThreshold = Param("Intraday MACDThreshold",0,-5,5,0.1);
StopLoss = Param("Stop Loss",2,0.5,20,0.5)/100; //Trade stop loss
percentage
ProfitTarget = Param("Profit Target",10,1,50,1)/100; //Trade
profit target
Gapsize = Param("Gap Size", 5,1,20,1)/100;
//Compress bars to create 30 min stochastic and MACD.
TimeFrameSet(in15Minute*2);
r1 = Param( "Fast avg", 5, 2, 200, 1 );
r2 = Param( "Slow avg", 13, 2, 200, 1 );
r3 = Param( "Signal avg", 6, 2, 200, 1 );
ml = MACD(r1, r2);
sl = Signal(r1,r2,r3);
mh=ml-sl;

periods = Param( "Periods", 15, 1, 200, 1 );
Ksmooth = Param( "%K avg", 3, 1, 200, 1 );
HS = StochK( periods , Ksmooth);
TimeFrameRestore();

//Bring them down to current timeframe
IDStoch = TimeFrameExpand(HS,in15Minute*2,expandFirst);
IDMACD = TimeFrameExpand(MH,in15Minute*2,expandFirst);

//Cumulative Volume Calculations
D = Day();
CV[0]=V[0];
for(i=1;i<BarCount;i++)
{if(D[i] == D[i-1])
{CV[i]=V[i]+CV[i-1];
}
else
{CV[i]=V[i];
}
}
FRVPercent = Param("FRVPercent",200,1,500,5)/100;

//The following items are treated as static variables so I can pass
them automatically to my cumulative volume indicator
//StaticVarSet("PrevLBDU",PrevLBDU); //What percentage of dry up
volume is treated as a buy signal?
StaticVarSet("VolTime",ParamTime("Time to Volume Breakout","11:00"));
//Before what time must DU Volume be exceeded?

TodaysOpen = TimeFrameGetPrice("O",inDaily,0,expandFirst);
PrevDayClose = TimeFrameGetPrice("C",inDaily,-1);
NoGap = abs((TodaysOpen-PrevDayClose)/PrevDayClose) <= GapSize;

VolTime = StaticVarGet("VolTime");
DUVolExceeded = (TimeNum() <= VolTime AND CV > PrevLBDU);

//Code below records when all buy triggers are satisfied
PurchTrigger = DryupSignal AND NOGAP AND DUVolExceeded AND IDStoch >
IDStochThreshold AND IDMACD > IDMACDThreshold AND C >
TimeFrameGetPrice("C",inDaily,-1);
TriggerExecuted = Flip(PurchTrigger,Day()!=Ref(Day(),-1)); //Set a
flag when purchase occurs, to allow for buyprice, etc. to be plotted
on price window.
FRVReached = CV>=FRV;

//Hold the buy prices, etc so we can plot them. Assume that C is the
buy price(indicator only)
BPrice = IIf(TriggerExecuted,ValueWhen(PurchTrigger AND NOT
Ref(PurchTrigger,-1),C),Null);
SLoss = IIf(TriggerExecuted,ValueWhen(PurchTrigger AND NOT
Ref(PurchTrigger,-1),C*(1-StopLoss)),Null);
PTarget = IIf(TriggerExecuted,ValueWhen(PurchTrigger AND NOT
Ref(PurchTrigger,-1),C*(1+ProfitTarget)),Null);

//--PLOT STATEMENTS FOR PRICE CHART ONLY--
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g,
Lo %g, Close %g (%.1f%%)\n {{VALUES}}", O, H, L, C, SelectedValue(
ROC( C, 1 ) ) ));
Plot( C, "Close", IIf(Purchtrigger AND NOT
Ref(PurchTrigger,-1),colorYellow,IIf(C>O,colorGreen,colorRed)),
styleNoTitle|ParamStyle("Style") | GetPriceStyle() );

//Next few lines are for plotting text.
dist = 1*ATR(1);
for(i=1;i<BarCount;i++)
{
if( Purchtrigger[i] AND NOT Purchtrigger[i-1] ) PlotText( "Buy\n" +
"Stoch: " + Prec(IDStoch[i],1) + "\nMACD: " + Prec(IDMACD[i],2) +
"\nPT: " + C[i]*1.1, i, L[ i ]-dist[i], colorYellow);
}

//Misc plots in price window
Plot(NoGap,"NOGAP",colorYellow,styleNoDraw|styleNoRescale);
Plot(Day()!=Ref(Day(),-1),"",colorWhite,styleOwnScale|styleHistogram);
Plot(PurchTrigger,"PurchTrigger",colorYellow,styleNoDraw|styleNoRescale);
Plot(IDStoch > IDStochThreshold
,"IDStoch",colorYellow,styleNoDraw|styleNoRescale);
Plot(IDMACD >
IDMACDThreshold,"IDMACD",colorYellow,styleNoDraw|styleNoRescale);
Plot(DUVolExceeded ,"DUVE",colorYellow,styleNoDraw|styleNoRescale);
Plot(C >
TimeFrameGetPrice("C",inDaily,-1),"C>C",colorYellow,styleNoDraw|styleNoRescale);
Plot(Day()!=Ref(Day(),-1),"",colorWhite,styleOwnScale|styleHistogram);
Plot(BPrice,"Bprice",colorYellow,styleLine);
Plot(Sloss,"SLoss",colorRed,styleLine|styleDashed);
Plot(PTarget,"PTarget",colorBrightGreen,styleLine|styleDashed|styleNoRescale);

Plot(CV,"CV",colorWhite,styleNoDraw|styleNoRescale);
Plot(PrevLBDU,"LBDU",colorYellow,styleNoDraw|styleNoRescale);
Plot(DryUpVolume,"AvgDU",colorPink,styleNoDraw|styleNoRescale);
Plot(FRV,"FRV",colorBrightGreen,styleNoDraw|styleNoRescale);
Plot(PeakV,"Peak",colorGold,styleNoDraw|styleNoRescale);

Plot(DayVol,"DayVol",IIf(indryup,colorWhite,ColorRGB(218,200,220)),styleArea|styleThick|styleLeftAxisScale);
Plot(IDU1,"DU1",colorWhite,styleNoDraw|styleNoRescale|styleLeftAxisScale);
Plot(IDU2,"DU2",colorWhite,styleNoDraw|styleNoRescale|styleLeftAxisScale);
Plot(IDU3,"DU3",colorWhite,styleNoDraw|styleNoRescale|styleLeftAxisScale);
Plot(IDU4,"DU4",colorWhite,styleNoDraw|styleNoRescale|styleLeftAxisScale);
Plot(IDU5,"DU5",colorWhite,styleNoDraw|styleNoRescale|styleLeftAxisScale);
Plot(DailyEMAV65,"EMAV65",colorPink,styleLine|styleThick|styleLeftAxisScale);

//Test outputs to Interpretation Window

//AUTO TRADE
PortfolioRiskPercent = Param("Portfolio Risk
Percent",0.015,0.001,0.1,0.001);
AutoTradeOn = ParamToggle("Auto Trade","OFF|ON"); //Only autotrade
when this is active. Safeguard. Off by default.
MaxDailyTrades = Param("Max Daily Trades",3,0,10,1);

OrdersPlaced = StaticVarGet("OrdersPlaced");
if(IsEmpty(StaticVarGet("OrdersPlaced")))
{StaticVarSet("OrdersPlaced",0);
}

Ask_Price = GetRTData("Ask");
Bid_Price = GetRTData("Bid");
Last_Price = GetRTData("Last");
"Last Price = " + Last_Price;
"Ask Price = " + Ask_Price;
"Bid Price = " + Bid_Price;
Spread = Ask_Price - Bid_Price;
"Spread = " + Spread;
SpreadPercent = Prec((Spread / Bid_Price)*100,2);
"Spread Percent = " + SpreadPercent + "%";

TestBuy = ParamTrigger("Test Order", "Execute"); //This is a one
shot test code. If I want to test a bit of the autotrading code, I
stick testbuy in as the
//'if' value and then can activate the code by pressing
'execute' in the parameters dialog box.
//When autotrading, need to use lastvalue (which is a number), as
arrays don't work. Also stops old values triggering buys.
intrades = InWatchList(8); //Is the stock in the watchlist
where tickers with executed trades are placed.
Buy= (purchtrigger AND scan AND NOT intrades);

ibc = GetTradingInterface("IB");
BP = StrToNum(ibc.getaccountvalue("AvailableFunds"))*2;
AC = StrToNum(ibc.getaccountvalue("NetLiquidation")); //current equity

Risk = ac* PortfolioRiskPercent;
PurchasingPower = (StrToNum(ibc.getaccountvalue("RegTEquity")) -
StrToNum(ibc.getaccountvalue("RegTMargin")))*1.8;
orderid = ""; //Clear order id in case orders have been previously
submitted.
NumShares = Risk/(C*StopLoss);
PositionSize = C*NumShares;
NumLots = LastValue(IIf(PositionSize < PurchasingPower, Numshares -
NumShares%100,(PurchasingPower/C)-(PurchasingPower/C)%100));
StopLossShares = Ask_Price*(1-StopLoss);
ProfitTargetShares = Ask_Price*(1+ProfitTarget);
"Is Connected = " + ibc.isconnected;
"Buying Power = " + BP;
"PurchasingPower = " + PurchasingPower;
"Risk = " + Risk;
"Account Balance = " + AC;
"Name = " + Name();
"Current No. shares owned = " + ibc.getpositionsize(Name());
"NumShares = " + NumShares;
"Raw Position Size = " + PositionSize;
"NumLots = " + NumLots;
"Position Size (in round lots) = " + Numlots * C;
if(AutoTradeOn)
{
if(ibc.getpositionsize(Name())==0 AND LastValue(Buy) AND
LastValue((Numlots*C) < PurchasingPower) AND LastValue(numlots) > 0
AND StaticVarGet("OrdersPlaced") <= MaxDailyTrades)
{orderid =
ibc.placeorder(Name(),"Buy",NumLots,"LMT",Ask_Price,0,"GTC",False);

ibc.placeorder(Name(),"SELL",NumLots,"STP",0,StopLossShares,"GTC",False,100,"",OrderID);

ibc.placeorder(Name(),"SELL",NumLots,"LMT",ProfitTargetShares,0,"GTC",True,100,"",OrderID);
if(StrToNum(ORderid) > 0)
{CategoryAddSymbol(Name(),categoryWatchlist,8);
StaticVarSet("OrdersPlaced",StaticVarGet("OrdersPlaced")+1);
//Remove the symbol so we don't get multiple buy orders.
}
}
}
"Orders Placed = " + StaticVarGet("OrdersPlaced");
Filter = InDryUp;
AddColumn(DayVOL,"Day Vol",1);
AddColumn(DailyEMAV65,"65 Day Avg",1);
AddColumn(IDU1,"DU1",1);
AddColumn(IDU2,"DU2",1);
AddColumn(IDU3,"DU3",1);
AddColumn(IDU4,"DU4",1);
AddColumn(IDU5,"DU5",1);

====================================================================

Kind Regards,

George.

--- In amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko" <groups@xxx> wrote:
>
> Hello,
>
> Your formula is probably written in wrong way (highly inefficient)
> Without showing it - no one is able to provide you any help.
>
> And no, you don't need several chart windows,
> you can use Foreign() function to access other symbols data.
> This is especially true for automated trading - you should
> NOT have more than one automatic trading formula running at the same
> time unless you are true EXPERT in programming, because
> having two or more automatic trading formulas running at the same
> time requires lots of bookkeeping, synchronization, etc, etc.
>
> Since you are asking such a basic question - it is pretty clear
> that you are not expert and you should rather develop your system
> in very small steps.
>
> Best regards,
> Tomasz Janeczko
> amibroker.com
> ----- Original Message -----

> From: "gpzany13" <gpzany13@xxx>
> To: <amibroker@xxxxxxxxxxxxxxx>
> Sent: Saturday, July 21, 2007 2:08 AM
> Subject: [amibroker] Multiple Stock charts...
>
>
> > Hi everyone,
> >
> > I am trying to run an afl script on one minute candle charts for
> > approximately 15 stock symbols.
> >
> > Originally, I had the symbols in a watch list, but if I am correct,
> > only the active symbol in the chart window has the afl script active
> > to autoexecute signals into IBcontroller...
> >
> > So I opened a blank chart per symbol, and CPU usage went +60% peaking
> > regularly at +90%, with Amibroker seriously slowing down...
> >
> > Is there a way I can have my script running in real time on multiple
> > symbols, executing trades without having that many chart windows open?
> > Or is there another way of doing this...
> >
> > Thanks in advance,
> >
> > George.
> >
> >
> >
> > 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
> >
> >
> >
> >
> >
>


__._,_.___

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





SPONSORED LINKS
Investment management software Investment property software Investment software
Investment tracking software Return on investment software

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___