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

RE: [amibroker] Test Request



PureBytes Links

Trading Reference Links



Hi Everyone, 
        I have
just completed "Manual Stop Entry" indicator which may be
usefull for others. 
(If even just to examine the code to see how it works).
Also, I need some people to just let me know if it works for them -
Before I post
 it to the AFL archive. 
Use the parameters dialog (CTRL-R) to adjust settings.
Code: (And Attached)
// Manual Stop
Entry V1.00
//
Created              1/5/04
//
Author               OzFalcon
(Michael.S.G.).
//
Purpose              Manualy
Enter & Track Trades.
//
Type         Indicator
//
Notes                Use
Parameters (CTRL-R) to Set & Save.
//
Notes                
(Buybar is set with Currently Selected Bar.)
// Set Trade Equity
Cash =
Param("6.Cash",0,0,10000,0.01);
Comm =
Param("7.Comm",0,0,50,0.01);
// Plot
Price & Turnover.
Color =
IIf(O
> C, colorBlack, colorLightYellow);
Plot(
Close,
"Price",
color, styleCandle );
PlotForeign(
GetBaseIndex(),
GetBaseIndex(),
colorAqua,  styleLine | styleThick |
styleOwnScale); 
Turnover = (V*C);
BarColor = 
IIf(
Turnover >
Ref(Turnover,-1), 
colorRed ,
/* up
volume */ 
IIf(
Turnover <
Ref(Turnover,-1), 
colorOrange,
/* down
volume */
                    
colorGreen
/*otherwise*/ ));
Plot( Turnover, "Turnover", BarColor, styleHistogram | styleThick | styleOwnScale);
// Set Global Variables.
BC = BarCount-1;
BNUM = BarIndex();
// Set Default BuyBar & BuyAt etc.
SelectedBar = SelectedValue(BNUM); 
BuyBar = SelectedBar;
BuyAt = Param("1.BuyAt",0,0,100,0.01);
EvenStop = Param("2.EvenStop",1,0,100,0.01); //Percentage Of Buy Price
ProfitStop = Param("3.ProfitStop",2,0,100,0.01); //Percentage of Buy Price.
LossStop = Param("4.LossStop",2,0,100,0.01); //Percentage of Buy Price.
TrailStop = Param("5.TrailStop",2,0,100,0.01); //Percentage from Highest High since BuyBar.
// Overide Default BuyBar & BuyAt if previously Set or Write setup.
LockSet = Param("Lock/Set",False,False,True,1);
TrailName = "Data/" + Name()+"~Stop.txt";
if (LockSet == False)
        {
        fh = fopen( TrailName, "r"); 
        if( fh ) 
                { 
                BuyBar = StrToNum(fgets( fh ));   
                BuyAt  = StrToNum(fgets( fh ));
                EvenStop = StrToNum(fgets( fh ));
                ProfitStop = StrToNum(fgets( fh ));
                LossStop = StrToNum(fgets( fh ));
                TrailStop = StrToNum(fgets( fh ));
                Cash = StrToNum(fgets( fh ));
                Comm = StrToNum(fgets( fh ));
                fclose( fh );
                TitleS="ReadFile"; 
                }
        else 
                { 
                printf("Trail Not Set\n");
                BuyBar=BC;
                BuyAt=C[BuyBar];
                TitleS="NoFile";
                }
        }       
else
        {
        BuyBar = IIf ((BuyBar == 0),BC,BuyBar);
        BuyAt  = IIf ((BuyAt  == 0),C[BuyBar],BuyAt);
        TitleS = "SaveFile";
        fh = fopen( TrailName, "w"); 
        if( fh ) 
                { 
                fputs( StrFormat("%.00f\n",BuyBar), fh ); 
                fputs( StrFormat("%.02f\n",BuyAt ), fh );
                fputs( StrFormat("%.02f\n",EvenStop ), fh ); 
                fputs( StrFormat("%.02f\n",ProfitStop ), fh ); 
                fputs( StrFormat("%.02f\n",LossStop ), fh ); 
                fputs( StrFormat("%.02f\n",TrailStop ), fh );  
                fputs( StrFormat("%.02f\n",Cash ), fh );  
                fputs( StrFormat("%.02f\n",Comm ), fh );  
                fclose( fh ); 
                }
        }
// Plot Vertical & Horizontal Buy Bar/Price. (Blue/Yellow)
VLine = IIf(BuyBar==BNUM,1,0);
        Plot (VLine ,"BuyBar", colorBlue, styleHistogram | styleOwnScale,0,1);
x0 = Buybar-1 ; x1 = BuyBar+1 ;
y0 = BuyAt; y1 = BuyAt;
Hline = LineArray(x0,y0,x1,y1,3);
        Plot(HLine ,"BuyPrice",colorYellow,styleLine);
// Plot Trade Trend (BuyBar to Current Bar - Blue Dashed Line).
x0 = Buybar ; x1 = BC ;
y0 = BuyAt; y1 = C[BC];
Hline = LineArray(x0,y0,x1,y1,1);
        Plot(HLine ,"TradeTrend",colorLightBlue,styleDots);
// Plot Break Even Horizontal (Green).
x0 = Buybar-1 ; x1 = BuyBar+1 ;
y0 = BuyAt*(1+(EvenStop/100)) ;y1=y0;
Hline = LineArray(x0,y0,x1,y1,1);
        Plot(HLine ,"EvenStop",colorGreen,styleLine);
// Plot Profit Stop Horizontal (Orange)
x0 = Buybar-1 ; x1 = BuyBar+1 ;
y0 = BuyAt*(1+(ProfitStop/100)) ;y1=y0;
Hline = LineArray(x0,y0,x1,y1,1);
        Plot(HLine ,"ProfitStop",colorOrange,styleLine);
// Plot Loss Stop Horizontal (Red).
x0 = Buybar-1 ; x1 = BuyBar+1 ;
y0 = BuyAt*(1-(LossStop/100)) ;y1=y0;
Hline = LineArray(x0,y0,x1,y1,1);
        Plot(HLine ,"LossStop",colorRed,styleLine);
// Plot Trail Stop Trend (Highest High to Current Bar - Orange Dashed Line).
ThisIsBuyBar = (BNUM == BuyBar);
TrailPeak = BC-(LastValue(HighestSinceBars(ThisIsBuyBar,High,1)));
ThisIsTrailPeak = (BNUM == TrailPeak);
PeakValue = High[TrailPeak];
x0 = TrailPeak; y0=PeakValue;
x1 = SelectedBar; y1=C[SelectedBar];
Line = LineArray(x0,y0,x1,y1,0);
Plot(Line,"TrailStop",colorOrange,styleDots);
TrailValue = ((y1/y0)-1)*100;
// Calculate Holding Stats.
Avail = Cash-Comm;
Qty = int((Avail/BuyAt));
Remain = Avail-(Qty*BuyAt);
Value = ((Close*Qty)-Comm)+Remain;
Change = Value-Cash;
Gain = ((Value/Avail)-1)*100;
// Dynamic Title
_N(Title = "\\c29"+
"Trail Stop "+
"\\c32"+ Date()+ 
"\\c29 Ticker: \\c32"+Name()+
"\\c29 Index: \\c24"+GetBaseIndex()+
"\n"+
"\\c38 Open \\c01"+O+
"\\c38 Hi \\c01"+H+
"\\c38 Low \\c01"+L+
"\\c38 Close \\c01"+C+
"\n"+
"\\c38 TurnOver \\c24"+WriteVal(TurnOver,1)+
"\\c29  SelectedBar: \\c32"+ SelectedBar+
"\n"+
"\\c38 Cash \\c01"+Cash+
"\\c38 Comm \\c01"+Comm+
"\\c38 Qty \\c01"+Qty+
"\n"+
"\\c38 Vaule \\c01$"+Value+
"\\c38 Change \\c01$"+Change+
"\\c38 Gain \\c01"+Gain+"%"+
"\n"+
"\\c29 TrailPeekBar: \\c01"+TrailPeak+
"\\c29 Trail \\c01"+TrailValue+"%"+
"\n" + TitleS +
"");
// End.



Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html








Yahoo! Groups Sponsor


  ADVERTISEMENT 












Yahoo! Groups Links
To visit your group on the web, go to:http://groups.yahoo.com/group/amibroker/ 
To unsubscribe from this group, send an email to:amibroker-unsubscribe@xxxxxxxxxxxxxxx 
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.








// Manual Stop Entry V1.00
// Created		1/5/04
// Author		OzFalcon (Michael.S.G.).
// Purpose		Manualy Enter & Track Trades.
// Type		Indicator
// Notes		Use Parameters (CTRL-R) to Set & Save.
// Notes		 (Buybar is set with Currently Selected Bar.)

// Set Trade Equity
Cash = Param("6.Cash",0,0,10000,0.01);
Comm = Param("7.Comm",0,0,50,0.01);

// Plot Price & Turnover.
Color = IIf(O > C, colorBlack, colorLightYellow);
Plot( Close, "Price", color, styleCandle );
PlotForeign( GetBaseIndex(), GetBaseIndex(), colorAqua,  styleLine | styleThick | styleOwnScale); 
Turnover = (V*C);
BarColor = 
IIf( Turnover > Ref(Turnover,-1),  colorRed , /* up volume */ 
IIf( Turnover < Ref(Turnover,-1),  colorOrange, /* down volume */
                     colorGreen /*otherwise*/ ));
Plot( Turnover, "Turnover", BarColor, styleHistogram | styleThick | styleOwnScale);

// Set Global Variables.
BC = BarCount-1;
BNUM = BarIndex();

// Set Default BuyBar & BuyAt etc.
SelectedBar = SelectedValue(BNUM); 
BuyBar = SelectedBar;
BuyAt = Param("1.BuyAt",0,0,100,0.01);
EvenStop = Param("2.EvenStop",1,0,100,0.01); //Percentage Of Buy Price
ProfitStop = Param("3.ProfitStop",2,0,100,0.01); //Percentage of Buy Price.
LossStop = Param("4.LossStop",2,0,100,0.01); //Percentage of Buy Price.
TrailStop = Param("5.TrailStop",2,0,100,0.01); //Percentage from Highest High since BuyBar.

// Overide Default BuyBar & BuyAt if previously Set or Write setup.
LockSet = Param("Lock/Set",False,False,True,1);
TrailName = "Data/" + Name()+"~Stop.txt";
if (LockSet == False)
	{
	fh = fopen( TrailName, "r"); 
	if( fh ) 
		{ 
		BuyBar = StrToNum(fgets( fh ));   
		BuyAt  = StrToNum(fgets( fh ));
		EvenStop = StrToNum(fgets( fh ));
		ProfitStop = StrToNum(fgets( fh ));
		LossStop = StrToNum(fgets( fh ));
		TrailStop = StrToNum(fgets( fh ));
		Cash = StrToNum(fgets( fh ));
		Comm = StrToNum(fgets( fh ));
		fclose( fh );
		TitleS="ReadFile"; 
		}
	else 
		{ 
   		printf("Trail Not Set\n");
		BuyBar=BC;
		BuyAt=C[BuyBar];
		TitleS="NoFile";
		}
	}	
else
	{
	BuyBar = IIf ((BuyBar == 0),BC,BuyBar);
	BuyAt  = IIf ((BuyAt  == 0),C[BuyBar],BuyAt);
	TitleS = "SaveFile";
	fh = fopen( TrailName, "w"); 
	if( fh ) 
		{ 
		fputs( StrFormat("%.00f\n",BuyBar), fh ); 
		fputs( StrFormat("%.02f\n",BuyAt ), fh );
		fputs( StrFormat("%.02f\n",EvenStop ), fh ); 
		fputs( StrFormat("%.02f\n",ProfitStop ), fh ); 
		fputs( StrFormat("%.02f\n",LossStop ), fh ); 
		fputs( StrFormat("%.02f\n",TrailStop ), fh );  
		fputs( StrFormat("%.02f\n",Cash ), fh );  
		fputs( StrFormat("%.02f\n",Comm ), fh );  
		fclose( fh ); 
		}
	}

// Plot Vertical & Horizontal Buy Bar/Price. (Blue/Yellow)
VLine = IIf(BuyBar==BNUM,1,0);
	Plot (VLine ,"BuyBar", colorBlue, styleHistogram | styleOwnScale,0,1);
x0 = Buybar-1 ; x1 = BuyBar+1 ;
y0 = BuyAt; y1 = BuyAt;
Hline = LineArray(x0,y0,x1,y1,3);
	Plot(HLine ,"BuyPrice",colorYellow,styleLine);

// Plot Trade Trend (BuyBar to Current Bar - Blue Dashed Line).
x0 = Buybar ; x1 = BC ;
y0 = BuyAt; y1 = C[BC];
Hline = LineArray(x0,y0,x1,y1,1);
	Plot(HLine ,"TradeTrend",colorLightBlue,styleDots);

// Plot Break Even Horizontal (Green).
x0 = Buybar-1 ; x1 = BuyBar+1 ;
y0 = BuyAt*(1+(EvenStop/100)) ;y1=y0;
Hline = LineArray(x0,y0,x1,y1,1);
	Plot(HLine ,"EvenStop",colorGreen,styleLine);

// Plot Profit Stop Horizontal (Orange)
x0 = Buybar-1 ; x1 = BuyBar+1 ;
y0 = BuyAt*(1+(ProfitStop/100)) ;y1=y0;
Hline = LineArray(x0,y0,x1,y1,1);
	Plot(HLine ,"ProfitStop",colorOrange,styleLine);

// Plot Loss Stop Horizontal (Red).
x0 = Buybar-1 ; x1 = BuyBar+1 ;
y0 = BuyAt*(1-(LossStop/100)) ;y1=y0;
Hline = LineArray(x0,y0,x1,y1,1);
	Plot(HLine ,"LossStop",colorRed,styleLine);

// Plot Trail Stop Trend (Highest High to Current Bar - Orange Dashed Line).
ThisIsBuyBar = (BNUM == BuyBar);
TrailPeak = BC-(LastValue(HighestSinceBars(ThisIsBuyBar,High,1)));
ThisIsTrailPeak = (BNUM == TrailPeak);
PeakValue = High[TrailPeak];
x0 = TrailPeak; y0=PeakValue;
x1 = SelectedBar; y1=C[SelectedBar];
Line = LineArray(x0,y0,x1,y1,0);
Plot(Line,"TrailStop",colorOrange,styleDots);
TrailValue = ((y1/y0)-1)*100;

// Calculate Holding Stats.
Avail = Cash-Comm;
Qty = int((Avail/BuyAt));
Remain = Avail-(Qty*BuyAt);
Value = ((Close*Qty)-Comm)+Remain;
Change = Value-Cash;
Gain = ((Value/Avail)-1)*100;

// Dynamic Title
_N(Title = "\\c29"+
"Trail Stop "+
"\\c32"+ Date()+ 
"\\c29 Ticker: \\c32"+Name()+
"\\c29 Index: \\c24"+GetBaseIndex()+
"\n"+
"\\c38 Open \\c01"+O+
"\\c38 Hi \\c01"+H+
"\\c38 Low \\c01"+L+
"\\c38 Close \\c01"+C+
"\n"+
"\\c38 TurnOver \\c24"+WriteVal(TurnOver,1)+
"\\c29  SelectedBar: \\c32"+ SelectedBar+
"\n"+
"\\c38 Cash \\c01"+Cash+
"\\c38 Comm \\c01"+Comm+
"\\c38 Qty \\c01"+Qty+
"\n"+
"\\c38 Vaule \\c01$"+Value+
"\\c38 Change \\c01$"+Change+
"\\c38 Gain \\c01"+Gain+"%"+
"\n"+
"\\c29 TrailPeekBar: \\c01"+TrailPeak+
"\\c29 Trail \\c01"+TrailValue+"%"+
"\n" + TitleS +
"");

// End.