|
本帖最後由 joshsmi 於 13-7-24 18:23 編輯
Stop writing "there is no function for this and there is no function for that" and "this seems to be impossible and that seems to impossible".
You can program everything! Learn how to code and look at the help file!
And since you are a total newbie here is a tip or one number one rule of programming:
Stop using the same expression or function over and over and over again (even more so if they are time consuming during processing). So put repeated calls to a variable! Otherwise you are limiting yourself.
// by joshsmi
OpenTime = 093000;
CloseTime = 160000;
tn = TimeNum();
mth = Month() == 7; // July only
MA1 = MA ( C, 10 );
MA2 = MA ( C, 50 );
CrossBuy = Cross ( MA1, MA2 );
CrossShort = Cross ( MA2, MA1 );
ExitTime = tn >= CloseTime; // compulsory Close position after 16:00
EntryTime = tn >= OpenTime AND tn < CloseTime; // Entry only between 09:00 AND 16:00
Buy = CrossBuy AND mth AND EntryTime;
Sell = CrossShort AND mth OR ExitTime;
Short = CrossShort AND mth AND EntryTime;
Cover = CrossBuy AND mth OR ExitTime;
BuyPrice = SellPrice = C;
ShortPrice = CoverPrice = C;
if ( Status( "action" ) == actionExplore )
{
// for exploration, not backtesting
Filter = Buy || Short;
AddColumn( IIf( Buy, BuyPrice, Null ), "BuyPrice", 1.4, colorLightYellow, colorDarkGreen );
AddColumn( IIf( Short, ShortPrice, Null ), "ShortPrice", 1.4, colorLightYellow, colorDarkRed );
}
//for PLOT only :::::::::::::::::::::::::::::::::::::::::::::
if( Status( "action" ) == actionIndicator )
{
// remove excessive signals
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );
Short = ExRem( Short, Cover );
Cover = ExRem( Cover, Short );
SetChartBkColor( colorBlack );
SetChartOptions( 0, chartShowDates );
SetBarFillColor( IIf( C > O, ColorRGB( 0, 75, 0 ), IIf( C <= O, ColorRGB( 75, 0, 0 ), colorLightGrey ) ) );
Plot( C, "", IIf( C > O, ColorRGB( 0, 255, 0 ), IIf( C <= O, ColorRGB( 255, 0, 0 ), colorLightGrey ) ), 64, 0, 0, 0, 0 );
Buycolor = colorGreen;
Sellcolor = colorOrange;
Shortcolor = colorRed;
Covercolor = colorLightBlue;
PlotShapes( Buy*shapeSmallUpTriangle, Buycolor, 0, L, -15 );
PlotShapes( Buy*shapeHollowSmallUpTriangle, colorLightGrey, 0, L, -15 );
PlotShapes( Buy*shapeHollowSmallCircle, Buycolor, 0, BuyPrice, 0 );
PlotShapes( Sell*shapeDownArrow, Sellcolor, 0, H, -15 );
PlotShapes( Sell*shapeHollowDownArrow, colorLightGrey, 0, H, -15 );
PlotShapes( Sell*shapeHollowSmallCircle, Sellcolor, 0, SellPrice, 0 );
Shortdist = IIf( Short AND Sell, -30, -15 );
PlotShapes( Short*shapeSmallDownTriangle, Shortcolor, 0, H, Shortdist );
PlotShapes( Short*shapeHollowSmallDownTriangle, colorLightGrey, 0, H, Shortdist );
PlotShapes( Short*shapeSmallCircle, Shortcolor, 0, ShortPrice, 0 );
Coverdist = IIf( Cover AND Buy, -30, -15 );
PlotShapes( Cover*shapeUpArrow, Covercolor, 0, L, Coverdist );
PlotShapes( Cover*shapeHollowUpArrow, colorLightGrey, 0, L, Coverdist );
PlotShapes( Cover*shapeSmallCircle, Covercolor, 0, CoverPrice, 0 );
dist = 1.20 * ATR( 7 );
pToggle = ParamToggle( "PlotText", "Disable|Enable", 1 );
firstbar = Status( "firstvisiblebar" );
lastbar = Min( BarCount, Status( "lastvisiblebar" ) );
for ( i = firstbar; i < lastbar; i++ )
{
if( Short[ i ] AND Sell[ i ] )
dist2[ i ] = 2 * dist[ i ];
else dist2[ i ] = dist[ i ];
if( Cover[ i ] AND Buy[ i ] )
dist3[ i ] = 2 * dist[ i ];
else dist3[ i ] = dist[ i ];
if ( Buy[ i ] ) if ( pToggle ) PlotText( "Buy\n@" + BuyPrice[ i ], i, L[ i ] - dist[ i ], Buycolor );
if ( Sell[ i ] ) if ( pToggle ) PlotText( "Sell\n@" + SellPrice[ i ], i, H[ i ] + dist[ i ], Sellcolor );
if ( Short[ i ] ) if ( pToggle ) PlotText( "Short\n@" + ShortPrice[ i ], i, H[ i ] + dist2[ i ], Shortcolor );
if ( Cover[ i ] ) if ( pToggle ) PlotText( "Cover\n@" + CoverPrice[ i ], i, L[ i ] - dist3[ i ], Covercolor );
}
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.2f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
// stripes
Colperiod = ParamColor( "Color of periodic stripes", colorDarkGrey );
Plot( EntryTime, "", Colperiod, styleArea | styleOwnScale | styleNoLabel, 0, 1, 0, -10 );
}
|
評分
-
查看全部評分
|