NexusFi: Find Your Edge


Home Menu

 





buy next bar... and set stop immediately and not for the bar after


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one Nicolas11 with 4 posts (6 thanks)
    2. looks_two Jura with 2 posts (8 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 ejtrader with 1 posts (2 thanks)
      Best Posters
    1. looks_one Jura with 4 thanks per post
    2. looks_two Big Mike with 2 thanks per post
    3. looks_3 ejtrader with 2 thanks per post
    4. looks_4 Nicolas11 with 1.5 thanks per post
    1. trending_up 18,336 views
    2. thumb_up 20 thanks given
    3. group 7 followers
    1. forum 13 posts
    2. attach_file 7 attachments




 
Search this Thread

buy next bar... and set stop immediately and not for the bar after

  #11 (permalink)
 lbottan 
modena, Italy
 
Experience: Intermediate
Platform: Mc9+IB+iqfeed
Broker: IB
Trading: stocks, futures
Posts: 4 since Apr 2014
Thanks Given: 0
Thanks Received: 0

Hi,
i was reading your post here and got surprised by the standard MC stoploss function:

inputs: StopLossPct( .05 ) ;

SetStopShare ;
if MarketPosition = -1 then
SetStopLoss( EntryPrice * StopLossPct )
else
Buy To Cover ( "PctStopSX-eb" ) next bar at Close * ( 1 + StopLossPct ) stop ;

Basically it looks the function sens a BUY to cover even if no position is open and when a position is open it changes it with a setstoploss.

I am confused.

My target is to have a stop loss that acts on the same bar of the entry but at the same time i can't use barmagnifier (i use a continuos future and it is not allowed in MC).

What's the best way to achieve this?

If write this generic stoploss function does it make sense?

inputs:
LXStopLossPct(0.05),
SXStopLossPct(0.05),
Futures(true);

vars:
mlt(1);

If Futures then mlt = bigpointvalue;

SetStopShare;
if (MarketPosition = 1) and (LXStopLossPct > 0) then SetStopLoss(EntryPrice * LXStopLossPct * mlt);
if (MarketPosition = -1) and (SXStopLossPct > 0) then SetStopLoss(EntryPrice * SXStopLossPct * mlt);

if (MarketPosition = 0) and (LXStopLossPct > 0) then Sell ( "PctStopLX-eb" ) next bar at EntryPrice * ( 1 - (LXStopLossPct * mlt)) stop;
if (MarketPosition = 0) and (SXStopLossPct > 0) then Buy To Cover ( "PctStopSX-eb" ) next bar at EntryPrice * ( 1 + (SXStopLossPct * mlt)) stop;


In my view this make not much sense but the standard MC function looks similar to this.

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Better Renko Gaps
The Elite Circle
What broker to use for trading palladium futures
Commodities
Quantum physics & Trading dynamics
The Elite Circle
MC PL editor upgrade
MultiCharts
ZombieSqueeze
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
26 thanks
ApexTraderFunding.com experience and review
13 thanks
Trading with Intuition
12 thanks
EG Indicators
11 thanks
What is Markets Chat (markets.chat) real-time trading ro …
9 thanks
  #12 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

lbottan,

you should try your code on a simulation account to see how it works. I would slightly rewrite it to this (note that I didn't check/test your code, it's just a modification of what you wrote). There is a difference in both codes in that yours does only send the buy to cover or sell order for Marketposition = 0.
Without the BarMagnifier and depending on the resolution you work with, the results shouldn't be trusted and carefully checked with simulted (at least, live would be better) forward testing! There is simply too much information missing in bar and the program tends to make wrong assumptions then - for example was a stop hit first before the target was reached or vice versa.

 
Code
inputs:
LXStopLossPct(0.05),
SXStopLossPct(0.05),
Futures(true);

vars:
mlt(1);

If Futures then mlt = bigpointvalue;

SetStopShare;

if (LXStopLossPct > 0)  then
begin
   if (MarketPosition = 1) then 
              SetStopLoss(EntryPrice * LXStopLossPct * mlt)
   else
              Sell ( "PctStopLX-eb" ) next bar at EntryPrice * ( 1 - (LXStopLossPct * mlt)) stop;
end ;

if (SXStopLossPct > 0) then
begin
   if (MarketPosition = -1) then 
              SetStopLoss(EntryPrice * SXStopLossPct * mlt)
   else
               Buy To Cover ( "PctStopSX-eb" ) next bar at EntryPrice * ( 1 + (SXStopLossPct * mlt)) stop;
end ;
Regards,
ABCTG


lbottan View Post
Hi,
i was reading your post here and got surprised by the standard MC stoploss function:

inputs: StopLossPct( .05 ) ;

SetStopShare ;
if MarketPosition = -1 then
SetStopLoss( EntryPrice * StopLossPct )
else
Buy To Cover ( "PctStopSX-eb" ) next bar at Close * ( 1 + StopLossPct ) stop ;

Basically it looks the function sens a BUY to cover even if no position is open and when a position is open it changes it with a setstoploss.

I am confused.

My target is to have a stop loss that acts on the same bar of the entry but at the same time i can't use barmagnifier (i use a continuos future and it is not allowed in MC).

What's the best way to achieve this?

If write this generic stoploss function does it make sense?

inputs:
LXStopLossPct(0.05),
SXStopLossPct(0.05),
Futures(true);

vars:
mlt(1);

If Futures then mlt = bigpointvalue;

SetStopShare;
if (MarketPosition = 1) and (LXStopLossPct > 0) then SetStopLoss(EntryPrice * LXStopLossPct * mlt);
if (MarketPosition = -1) and (SXStopLossPct > 0) then SetStopLoss(EntryPrice * SXStopLossPct * mlt);

if (MarketPosition = 0) and (LXStopLossPct > 0) then Sell ( "PctStopLX-eb" ) next bar at EntryPrice * ( 1 - (LXStopLossPct * mlt)) stop;
if (MarketPosition = 0) and (SXStopLossPct > 0) then Buy To Cover ( "PctStopSX-eb" ) next bar at EntryPrice * ( 1 + (SXStopLossPct * mlt)) stop;


In my view this make not much sense but the standard MC function looks similar to this.


Follow me on Twitter Reply With Quote
  #13 (permalink)
trickortrade
London
 
Posts: 3 since Aug 2017
Thanks Given: 9
Thanks Received: 0



Nicolas11 View Post
I have thought again about this issue...

My rephrased question is the following: After having entered "at market" (= at the open), is it possible to have a stop loss triggered on the same bar as the said entry?

My conclusion is: it depends on the way the stop loss is coded.

1. With a manual stop loss, answer is NO.
.....

2. With a built-in stop loss (SetStopLoss), answer is YES.

[CODE]Variables:
TickSize ( MinMove / PriceScale );

if MarketPosition = 0 and H < H[1] and L > L[1] {inside bar} then begin
Buy ("Entry LONG") next bar at market;
SetStopLoss(5 * TickSize * BigPointValue);
end;

Thanks for sharing this. That was easy for me to implement and adjust in my code (even several years after you posted this!)

Reply With Quote
  #14 (permalink)
 Speculationist 
Calgary, Alberta/Canada
 
Experience: Advanced
Platform: Tradestation, Multicharts
Broker: IB, AMP
Trading: Stocks, ES, NQ
Posts: 6 since Sep 2012
Thanks Given: 2
Thanks Received: 0

I have been struggling around this issue for years and in one swift moment this thread just solved it for me.

"When the student is ready the master will appear" haha. Thanks!!!

Reply With Quote




Last Updated on November 11, 2019


© 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