NexusFi: Find Your Edge


Home Menu

 





Need Help with code


Discussion in Platforms and Indicators

Updated
    1. trending_up 2,331 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 3 posts
    2. attach_file 0 attachments




 
Search this Thread

Need Help with code

  #1 (permalink)
sr114
Kolkata+India
 
Posts: 27 since Aug 2012
Thanks Given: 10
Thanks Received: 1

Hello Forum

this indi is based on the slope of tema of tema of the price and the entry and exit is based on the slope factorhat tema .

its working but need some rectification or fine tuning in the code. these are:

1. to lock the profit earned in an active trade (either long or short) [ set as 5% from the highest profit earned]

2. stoploss - to get protection from adverse situation. ( applied Applystoploss function]


this profit locking is the most important part - never intend to lose the profit earned . so a certain percentage must be locked or the trade reversed to take the profit from the board.

also the system will forcibly reverse an active trade at a predefined time

the profit calculation part - i like to get the profit calculation for the new day and not the continuation of the previous day trade and the profit calculation therein.

looking for the help

posting the code - pls help me to fine tune it by rectifying it


Quoting 
_SECTION_BEGIN("Background_Setting");
SetChartBkGradientFill( ParamColor("BgTop", colorBlack),
ParamColor("BgBottom", colorDarkGrey),ParamColor("TitleBack",colorBlack));
SetChartBkColor(ParamColor("Outer Panel",colorPaleBlue));
SetChartOptions(0,chartShowArrows|chartShowDates);

SetBarFillColor(IIf(C>O,ParamColor("Candle UP Color", colorGreen),IIf(C<=O,ParamColor("Candle Down Color", colorRed),colorLightGrey)));
Plot(C,"",IIf(C>O,ParamColor("Wick UP Color", colorDarkGreen),IIf(C<=O,ParamColor("Wick Down Color", colorDarkRed),colorLightGrey)),64,0,0,0,0);

grid_day = Day()!=Ref(Day(),-1);
Plot(grid_day,"",colorGrey40,styleHistogram|styleDots|styleNoLabel|styleOwnScale);
_SECTION_END();

_SECTION_BEGIN("Parameters");
messageboard =ParamToggle("Message Board","Show|Hide",0);

beginTradeTime= Param("Strt Time",091700,091500,151000,10);
endTradeTime= Param("End Time",151500,091500,151000,10);

EndDay = ParamTime( "No trade after ", "15:10:00" );
EndDay2 = ParamTime( "close position ", "15:10:00" );

tn = TimeNum();
dn = DateNum();
Exit = Ref( tn < EndDay2, -1 ) AND ( tn >= EndDay2 OR dn < Ref( dn, 1 ) );

_SECTION_END();

_SECTION_BEGIN("trade system");

fact=U=Param("Main Curve Factor > 0",100,10,2000,1);
fact2=P=Param("Support Curve Factor..0-100",10,0,100,1);

ST=(P*U/100);
tMONITOR= TEMA(C,10);
tslow=TEMA(TEMA(Close,10),10);

Slptslow = (1000000*((tslow- Ref(tslow, -1))/tslow));

slptmonitor= (1000000*((tmonitor- Ref(tmonitor, -1))/tmonitor));

//Plot (tmonitor, "", colorGold, ParamStyle("Style"));
//Plot (tslow,"", colorWhite,ParamStyle(" Slope Style"));

Buy = Sell = Short = Cover = 0;

Buy = slptslow > fact AND Tn<EndDay;
Short = slptslow <-fact AND Tn<EndDay;

//Sell= ((Short) OR slptslow < ST ) OR exit; ;
//Cover= ((Buy) OR slptslow > ST ) OR exit;

Buysetup =Flip(Buy,Short);
Shortsetup =Flip(Short,Buy);

Sell = Shortsetup OR exit;
Cover = Buysetup OR exit;

ApplyStop(stopTypeTrailing ,2,Optimize( "max. profit stop level", 5, 2, 10, 1 ),1,False,0); // stop loss trailing of 5 % of the profit
ApplyStop(stopTypeLoss,stopModePercent,Optimize( "max. loss stop level", 5, 2, 10, 1 ),True,0);

Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);

SellPrice1=ValueWhen(Sell,H,1);
BuyPrice1=ValueWhen(Buy,L,1);
ShortPrice1=ValueWhen(Short,H,1);
CoverPrice1=ValueWhen(Cover,L,1);

BuyPrice = ValueWhen(Buy,BuyPrice1); bp=NumToStr(BuyPrice,1.2);
ShortPrice = ValueWhen(Short,shortPrice1); shp=NumToStr(ShortPrice,1.2);
SellPrice = ValueWhen(Sell,sellPrice1);
CoverPrice = ValueWhen(Cover,coverPrice1);

Long=Flip(Buy,Sell);
Shrt=Flip(Sell,Buy);

GraphXSpace=10;

/*
printf("\nBuy = " + NumToStr(Buy, 1.2) +
" Sell = " + NumToStr(Sell, 1.2) +
" Short = " + NumToStr(Short, 1.2) +
" Cover = " + NumToStr(Cover, 1.2) + "\n");

BuyInd = LastValue(Buy);
ShortInd = LastValue(Short);
SellInd = LastValue(Sell);
CoverInd = LastValue(Cover);

_TRACE("#, Indicators 2, Static, BuyInd = " + NumToStr(BuyInd,1.0) +
", SellInd = " + NumToStr(SellInd, 1.0) +
", ShortInd = " + NumToStr(ShortInd, 1.0) +
", CoverInd = " + NumToStr(CoverInd, 1.0) );*/

PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorAqua, layer = 0,yposition = Low, offset = -10);
PlotShapes( IIf( Short, shapeDownArrow, shapeNone ), colorRed, layer = 0, yposition = High, offset = -10);

PlotShapes( IIf(Cover, shapeHollowUpArrow,shapeNone), colorAqua, layer = 0,yposition = Low, offset = 10);
PlotShapes( IIf(Sell,shapeHollowDownArrow,shapeNone), colorPink, layer = 0, yposition = High, offset = -10);

//profit calculation
prf_ln= NumToStr((C-BuyPrice),1.2);
prf_sh= NumToStr((SellPrice-C),1.2);

//total equity calculation
firstTradeBarOfDay = TimeNum() >= beginTradeTime ;
firstTradeBarOfDay = firstTradeBarOfDay - Ref(firstTradeBarOfDay,-1);

inBuy1 = Flip(Buy,Sell);
inShort1 = Flip(Short,Cover);
totalPositions = IIf(inBuy1,1,0) * 1 + IIf(inShort1,-1,0) * 1;
actionAtBar = totalPositions - Ref(totalPositions,-1);

tc2 = TimeNum() >= beginTradeTime AND TimeNum() <= 151000;
eq1 = totalPositions * 1 * (C - Ref(C,-1));
eq2 = actionAtBar * 1 * (C - Ref(C,-1));
price_entry_exit = IIf(Buy,BuyPrice,IIf(Sell,SellPrice,IIf(Short,ShortPrice,IIf(Cover,CoverPrice,0))));
eq3 = actionAtBar * 1 * (C - price_entry_exit);
eqTotal = eq1 - eq2 + eq3 ;
rtEquity = tc2 * Sum(eqTotal,BarsSince(Ref(firstTradeBarOfDay,1) == 1));
StaticVarSet("eqSI_CAM",rtEquity);

_SECTION_END();


_SECTION_BEGIN("msg brd");

if
(messageboard == 0 )
{
SetChartOptions(0,chartShowArrows|chartShowDates);
GfxSelectFont( "Tahoma", 10, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );
GfxSelectSolidBrush( colorDarkGrey );
pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
Left = 1100;
width = 230;
x = 5;
x2 = 230;
y = pxHeight;

GfxSelectPen( colorLightBlue, 1);
GfxRoundRect( x, y - 120, x2, y , 7, 7 ) ;

GfxTextOut( Name(), 13, y-105);
GfxTextOut( Date(), 13, y-85);

GfxTextOut( ("" + WriteIf (Long AND NOT Buy, "Long At : "+(BP) + "","")), 13, y-65);
GfxTextOut( ("" + WriteIf (Shrt AND NOT Short, "Short At : "+(ShP) + "","")), 13, y-65);

GfxTextOut( ("" + WriteIf (Long AND NOT Buy, "Current P/L : "+prf_ln+" / lot","")), 13, y-45);
GfxTextOut( ("" + WriteIf (Shrt AND NOT Short, "Current P/L : "+ prf_sh+" / lot","")), 13, y-45);
GfxTextOut("Total P/L Today = Rs. " + NumToStr((rtequity),1.2)+" / lot", 13 , y-25);

}

_SECTION_END();

screen shots [ all time frame - 5 min - can also be reduced or range bars can be used ]

1. Scrip


2. parameters of the indi


3. another scrip [ same time frame - 5 min tf]


regards and thanks
sr114

Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
MC PL editor upgrade
MultiCharts
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
What broker to use for trading palladium futures
Commodities
Trade idea based off three indicators.
Traders Hideout
Cheap historycal L1 data for stocks
Stocks and ETFs
 
  #2 (permalink)
sr114
Kolkata+India
 
Posts: 27 since Aug 2012
Thanks Given: 10
Thanks Received: 1

Hello

is the code posted here is wrong?
will it not work properly?

if so, where is the mistake?

waiting for the answer.

rgds
sr114

Reply With Quote
  #3 (permalink)
sr114
Kolkata+India
 
Posts: 27 since Aug 2012
Thanks Given: 10
Thanks Received: 1


@Mod

please close this thread

sorted out the problem - so no need to ask for the help

thanx and rgds

Reply With Quote
  #4 (permalink)
tazosmr
tbilisi. Georgia
 
Posts: 5 since Apr 2014
Thanks Given: 0
Thanks Received: 0

and what was problem?..

Reply With Quote




Last Updated on May 13, 2014


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts