You are currently viewing in lite mode.
Click the link to view in full mode : Easy Language Stuff for Multicharts
dhpz
2008-Jun-07, 09:30 PM
Hey guys, hope some here can help me with my unsolved problems as follows:
1.) can someone bring an example how i have to write " SetExitOnClose ; " with specified times?
so i want to have my trading system stop giving signals on 5 minutes before market closes for example
my problems are with the normal SetExitOnClose ; he take me out in the last bar before close and also take me in again if the signal rule for entry is still valid
http://www5.file-upload.net/thumb/07.06.08/im2jtg.png (http://www.file-upload.net/view-900119/dhpz_1.png.html)
the next thing would be to add contracts if the gross profit increases and vice versa
so it should be like this
if grossprofit > ( x) then startamount add contract
if grossloss < ( -x) then startamount decrease number of contracts
as i'm not a well programmer and just had hard work to search everything together and do nothing find exactly about that last things
thank you if anybody can help me i appreciate that
regards dhpz
snafu
2008-Jun-09, 07:37 PM
inputs: YouTradingStartTime(900), YouTradingEndTime(1600); // time in 24h format
// position will be closed one bar after YouTradingEndTime(1600);
if currenttime_s <= YouTradingStartTime and currenttime_s <= YouTradingEndTime then begin
// Your CODE STARTS HERE
// Your CODE ENDS HERE
end else begin
if marketposition = 1 then sell next bar open;
if marketposition = -1then buy to cover next bar open;
end;
moteg
2008-Jun-09, 08:34 PM
Dear snafu,
How can we use EOD metastock data with multichart.
Pleae explain briefly. If possible through screenshot.
Regards,
(moteg)
JoeDOM_Admin
2008-Jun-09, 09:11 PM
Members:
Sorry for not having a programming/coding forum to discuss this.
I promise in the near future (once I finish programming the backup server and restart the Trader'sLibrary submissions), that I will crate some nice programming forums for the different trading platforms.
In the mean time, feel free to discuss everything related to programming here in this forum.
Syprik
2008-Jun-10, 12:40 AM
With respect to your second concern (# of contracts vs gross profit etc)...
Not sure if this input will be of any use, but I've been trading the ES future contract for quite a few years, and best most rudimentary money management approach I've been using is as follows:
Account Balance X discretionary Risk Factor (25-35% is popular in future trade industry).
Max loss per trade (stop loss): 2.0%
Ex.
Account Balance: $500k
Discretionary Risk Factor: 25%
Max Loss (Stop Loss) per trade: 2% of Account x Risk Factor
$500k * 0.25 = $100k
$125k * 0.02 = $2.5k stop loss
My current ES S&P500 system/strategy requires 3pt stop loss for maximum efficiency - 1 ES S&P500 contract = $50 per pt x 3pt stop = $150
$2.5k stop loss/$150 = 16 contracts should be traded
Say account balance climbs to 600k = $3k stop loss = 20 contracts to be traded.
Falls to 300k = $1.5k stop loss = 10 contracts etc etc
Besides the main account balance fluctuations, I will adjust my risk factor between 20 and 35% depending how well I'm trading and market volatility (higher vol generally = lower amount of contracts).
Some of the best traders like Larry Williams use this type model.
This should be very simple to automate if need be.
dhpz
2008-Jun-10, 01:51 AM
hey nice thanks admin to finally get this post for all available
first of all thank to snafu for your help with the code
i also got it to work for my use with this
//Entry Long
if 1=1
and Time > 1545
and Time < 2150
and xxxxxxxxxxxxxxxx
same for short allows my auto trader only to start firing 15 min after us market open (my timezone)
and don't allow any new signal after 2150 to trigger, and with setexitonclose flat it all
second was my break even stop should be +1 so that commissions are also flat
code for this
if MarketPosition = 1 then
SetBreakeven(( BreakevenFloorAmt )+0.1);
oh, now hes firing wild, market just dropped hard
see you after market guys ;)
__DBZ__
2008-Jun-10, 03:22 AM
Dear snafu,
How can we use EOD metastock data with multichart.
Pleae explain briefly. If possible through screenshot.
Regards,
(moteg)
Since Multicharts uses the same app to manage quotes than owndata called Quotemanager you shoud indicate on quote options the folder where the metastock data is and then use the MetaStock:thesymbol as symbol.
See here for more info http://www.tssupport.com/services/owndata/movies/metastock.shtml this is the way to do it on TS with Owndata and http://www.tssupport.com/multicharts/tutorials/MetaStock.htm this is the way to do it on multicharts.
dhpz
2008-Jun-10, 05:12 AM
inputs: YouTradingStartTime(900), YouTradingEndTime(1600); // time in 24h format
// position will be closed one bar after YouTradingEndTime(1600);
if currenttime_s <= YouTradingStartTime and currenttime_s <= YouTradingEndTime then begin
// Your CODE STARTS HERE
// Your CODE ENDS HERE
end else begin
if marketposition = 1 then sell next bar open;
if marketposition = -1then buy to cover next bar open;
end;
and here is what i use now
thank you for the info
//Tradingsession
if 1=1
and Time > 2155
and marketposition = 1 then sell ("Session End") next bar at Open;
if 1=1
and Time > 2155
and marketposition = -1 then buytocover ("Session Ending") next bar at Open;
dhpz
2008-Jun-10, 05:17 AM
and here sthg i like to share with you also
as i saw has mc or tn either no build in function that let you exit with various targets and / or let a position run ( let the runner run)
//Moneymanagment
var: initcontracts (0);
var: fstexit (0);
var: secexit (0);
var: thrdexit (0);
SetStopShare;
if Marketposition <> 0 then
begin
{calculate allocation of contracts}
fstexit = IntPortion ((MaxContracts/3)+0.9);
secexit = IntPortion ((MaxContracts/3)+0.6);
thrdexit = IntPortion ((MaxContracts/3)+0.3);
if barssinceentry > 1 then
begin
if StopLossAmt > 0 then SetStopLoss( StopLossAmt );
if marketposition > 0 then
begin
If Target1Amt > 0 and (CurrentContracts = MaxContracts) and high >= (entryprice + (Target1Amt/Bigpointvalue)) then sell ("T1L") fstexit contract next bar at market;
If Target2Amt > 0 and (CurrentContracts >= (MaxContracts - fstexit)) and high >= (entryprice + (Target2Amt/Bigpointvalue)) then sell ("T2L")secexit contract next bar at market;
end;
if marketposition < 0 then
begin
If Target1Amt > 0 and (CurrentContracts = MaxContracts) and low <= (entryprice - (Target1Amt/Bigpointvalue)) then buytocover ("T1S") fstexit contract next bar at market;
If Target2Amt > 0 and (CurrentContracts >= (MaxContracts - fstexit)) and low <= (entryprice - (Target2Amt/Bigpointvalue)) then buytocover ("T2S") secexit contract next bar at market;
end;
if Target2Amt > 0 then SetBreakeven(Target2Amt);
If Target3Amt > 0 then SetProfitTarget ( Target3Amt );
if MarketPosition = 1 then
SetBreakeven(( BreakevenFloorAmt )+0.1);
if DollarTrailingAmt > 0 then SetDollarTrailing( DollarTrailingAmt ) ;
if PctTrailingFloorAmt > 0 and PctTrailingPct > 0 then SetPercentTrailing( BreakevenFloorAmt, PctTrailingPct ) ;
if ExitOnClose = true then SetExitOnClose ;
end;
end;
that makes you available to choose your
T1
T2
T3
Break Even + 1 (Must be edited for various markets, for example Russel e-mini 0.1 works / have to know what each bigpointvalue is)
Trailing Stop - in $ or %
regards dhpz
moteg
2008-Jun-10, 11:41 PM
Since Multicharts uses the same app to manage quotes than owndata called Quotemanager you shoud indicate on quote options the folder where the metastock data is and then use the MetaStock:thesymbol as symbol.
See here for more info http://www.tssupport.com/services/owndata/movies/metastock.shtml this is the way to do it on TS with Owndata and http://www.tssupport.com/multicharts/tutorials/MetaStock.htm this is the way to do it on multicharts.
Dear DBZ,
Thanks for your guidance.
I try it.
(moteg)
dhpz
2008-Jun-11, 03:45 AM
does anyone have a idea (or code) to display the current open profit / loss and open orders with theire stop or trailing values in an alert window ?
so that they are shown in an extra field / pop up to the chart ?
i have the feeling that this should also be possible
thanks four your help
regards dhpz
dhpz
2008-Jun-14, 11:25 PM
With respect to your second concern (# of contracts vs gross profit etc)...
Not sure if this input will be of any use, but I've been trading the ES future contract for quite a few years, and best most rudimentary money management approach I've been using is as follows:
Account Balance X discretionary Risk Factor (25-35% is popular in future trade industry).
Max loss per trade (stop loss): 2.0%
Ex.
Account Balance: $500k
Discretionary Risk Factor: 25%
Max Loss (Stop Loss) per trade: 2% of Account x Risk Factor
$500k * 0.25 = $100k
$125k * 0.02 = $2.5k stop loss
My current ES S&P500 system/strategy requires 3pt stop loss for maximum efficiency - 1 ES S&P500 contract = $50 per pt x 3pt stop = $150
$2.5k stop loss/$150 = 16 contracts should be traded
Say account balance climbs to 600k = $3k stop loss = 20 contracts to be traded.
Falls to 300k = $1.5k stop loss = 10 contracts etc etc
Besides the main account balance fluctuations, I will adjust my risk factor between 20 and 35% depending how well I'm trading and market volatility (higher vol generally = lower amount of contracts).
Some of the best traders like Larry Williams use this type model.
This should be very simple to automate if need be.
thanks y that's what i also use but i need this one in easy language for my auto trader here
thats what i found the last days but don't get it to run so far
it's a function in multicharts but i don't know how to use and integrate it in the signal / indicator because the compiler gives me errors in the other functions
Input: EntFrac (0,75), {multiple of prior day's range for entering }
StopSz (1000), { size of money management stop in dollars }
PSMeth (3), { position sizing method, 1 - 12 }
Param1 (5.0), { Position sizing parameter #1 }
Param2 (0), { Position sizing parameter #2 }
BackTest (true), { true for back testing }
StEqty (50000), { starting account size, $ }
CurEqty (50000), { current account size, $ }
MxLoss (1000), { largest 1-contract/share/unit loss, $ }
MaxDD (2000), { largest 1-contract/share/unit drawdown, $ }
Stocks (False), { true if trading vehicle is a stock }
UseUnits (False), { true for trading in even units }
UnitSize (1), { # shares/contracts per unit }
UseMinN (true), { true --> # shares/contracts at least MinN }
MinN (1), { Minimum # of shares/contracts }
MaxN (100), { max allowable number of shares/contracts }
InitMarg (2000), { initial margin per contract for futures }
MargPer (100); { margin requirement in percent for stocks }
Var: EntPr (0), { Entry target price }
XitPr (0), { mm stop exit price }
TrRisk (0), { trade risk, $ }
NCon (0); { number of contracts }
TrRisk = StopSz;
{ Entry conditions }
NCon = PSCalc (PSMeth, Param1, Param2, BackTest, StEqty, CurEqty,
TrRisk, MxLoss, MaxDD, Stocks, UseUnits, UnitSize, UseMinN,
MinN, MaxN, InitMarg, MargPer);
EntPr = H + EntFrac * (H - L);
If C > C[1] then
Buy NCon contracts next bar at EntPr Stop;
{ Exit conditions }
Sell("MMStop") next bar at EntryPrice - TrRisk/BigPointValue stop;
If BarsSinceEntry >= 1 and open of next bar > EntryPrice then
Sell("ProfOpen") next bar at market;
dhpz
2008-Jun-15, 02:23 AM
so far so good boys 'n girls :)
finally i got a example code via google like this:
// Control System for testing e-Mini financial futures ES, NQ, ER2, EMD intra-day.
// WARNING: DO NOT TRADE THIS SYSTEM - IT TAKES RANDOM ENTRIES AND SHOULD ONLY
// BE USED AS A COMPARISON FOR A 'REAL' SYSTEM
// Setup: None - simply apply to any futures contract being tested
// Entry: Random side and time (between 9:35am and 3:00pm
// Position Sizing: Percent of notional equity based on initial stop
// Stops: Simple trailing stop
// Exit: Exit at end of day if not stopped out - no overnight positions
// Addition rules: None
// Notes:
// Does not include commissions or slippage in cumulative notional calculation
// All times EST.
// Date: 10/19/5
// Version: 1.0
// Author: Paul King
// Copyright 2005 PMKing Trading LLC www.pmkingtrading.com
// Schedule (EST):
// 9:30 AM Initialize trading for day and determine entry side and time (randomly)
// 9:35 AM Commence checking for random entry previously determined
// 3:00 PM Stop checking for entry
// 4:10 PM Exit if not stopped out
variables:
int lookback(0), // Number of bars in one session
int i(0), // A counter
int daysback(0), // Number of days to calculate range over
int entrybar(0), // Barnumber of trade entry
int positionsize(0), // Number of contracts to trade
int tradeperiod(0), // Average number of days between generated trades
int enterbar(0), // Randomly generated bar to enter random trade
int inposition(0), // Indicates whether in a position (>0 -> Long, <0 -> Short)
float dayrange(0), // Range of trading over daysback days
float stopprice(0), // Current stop price
float stopsize(0), // Distance of current stop from market
float percentrisk(0), // Percent of notional to risk per trade
float currentnotional(0), // Initial notional system allocation
float enterside(0), // Randomly generated side
float enterprice(0), // Entry price
bool entryok(False), // True if OK to enter a trade
// Use this input variable to run an 'optimization' the required number of iterations to see the variablility of returns
inputs: int simulationnumber(1);
// One time only actions
if BarNumber=1 then begin
currentnotional=40000; // Starting notional equity allocated to this strategy
end;
// Strategy constants
lookback=390; // Number of bars to calculate stop over
// Position sizing constants
percentrisk=0.02; // Start with 2% risk per position
// Parameters
tradeperiod=3; // Average number of days between trades
dayrange=3; // Number of days to calculate range over
// Setup entry parameters at 9:30 am
if (time = 0930) then begin
// Initialize positions - should be flat from previous day
inposition=0;
entryok=false;
// Calculate random entry
if round(random(tradeperiod),0)=tradeperiod
then begin
// OK to enter
entryok=true;
// Random bar to enter between now and 3:00 PM
enterbar=BarNumber+round(random(330),0);
// Random side >=0.5 -> long, <0.5 -> short
enterside=random(1);
end;
end;
// Calulate entry signal between 9:35 AM and 3:00 PM
if (time>0935 and time<1500) then begin
// Enter long
if (inposition=0 and entryok and CurrentBar=enterbar and enterside>=0.5) then
begin
// Store details
inposition=1;
stopsize=Round2Fraction(dayrange);
stopprice=Close-stopsize;
entrybar=CurrentBar;
enterprice=close;
// Calulate number of contracts
positionsize=round((currentnotional*percentrisk)/(stopsize*BigPointValue),0);
// Buy order
if (positionsize>=1) then
Buy ( "Long" ) positionsize contracts next bar at market
else inposition=0;
end;
// Enter short
if (inposition=0 and entryok and CurrentBar=enterbar and enterside<0.5)then
begin
// Store details
inposition=-1;
stopsize=Round2Fraction(dayrange);
stopprice=Close+stopsize;
entrybar=CurrentBar;
enterprice=close;
// Calulate number of contracts
positionsize=round((currentnotional*percentrisk)/(stopsize*BigPointValue),0);
//Sell order
if (positionsize>=1) then
Sell Short ( "Short" ) positionsize contracts next bar at market
else inposition=0;
end;
end;
// Check stop between 9:35 AM and 4:10 PM
if (time>0935 and time < 1610) then begin
// Test Stops
if (inposition<>0) then begin
// Long stop hit
if (inposition>0 and Close<=stopprice) then begin
Sell ("Long Stop Hit") positionsize contracts next bar at market;
inposition=0;
entryok=False;
entrybar=0;
// Modify notional
currentnotional=currentnotional+((close-enterprice)*positionsize*BigPointValue);
positionsize=0;
end;
// Short stop hit
if (inposition<0 and Close>=stopprice) then begin
buy to cover ("Short Stop Hit") positionsize contracts next bar at market;
inposition=0;
entryok=False;
entrybar=0;
// Modify Notional
currentnotional=currentnotional+((enterprice-close)*positionsize*BigPointValue);
positionsize=0;
end;
end;
// Adjust stops
// Long Stop
if (inposition>0) then stopprice=Highest(Close, CurrentBar-entrybar)-stopsize;
// Short Stop
if (inposition<0) then stopprice=Lowest(Close, CurrentBar-entrybar)+stopsize;
end;
// Close positions if not stopped out by ent of day (4:10 PM)
if (time=1610) then begin
if (inposition>0) then begin
sell ("Long EOD") positionsize contracts next bar at market;
inposition=0;
// Modify notional
currentnotional=currentnotional+((close-enterprice)*positionsize*BigPointValue);
positionsize=0;
end;
if (inposition<0) then begin
buy to cover ("Cover Short EOD") positionsize contracts next bar at market;
inposition=0;
// Modify notional
currentnotional=currentnotional+((enterprice-Close)*positionsize*BigPointValue);
positionsize=0;
end;
end;
where you can pick out what you need exactly for position sizing
i also got it run here on my stragegy but finally there is one error left
the exact modify national for my strategy
// Modify notional
currentnotional=currentnotional+(grossprofit-grossloss);
positionsize=0;
doesn't work
the insane system boost me up to 350 contracts after a few trades
so what can you advise me to take
i also tried and tested
currentnational=currentnational+netprofit
but it all boosts me up not correct
anyone out there with a little bit easylanguage expirience in multicharts please, need some help ;)
thank you in advance
regards dhpz
youseewealth.com - come wealthless, stay wealthy - yosewe
Thank you for visiting www.friendlytraders.com
---- Friendly Traders ----