NexusFi: Find Your Edge


Home Menu

 





Easylanguage/Multicharts still buying next bar even no more code to buy signal!


Discussion in MultiCharts

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




 
Search this Thread

Easylanguage/Multicharts still buying next bar even no more code to buy signal!

  #1 (permalink)
risaldeb
Hong Kong
 
Posts: 10 since Feb 2015
Thanks Given: 1
Thanks Received: 0

I am using Multicharts and Easylanguage program to code the following:
1. Buy if low[1]>Moving average
2. Limit orders from all signal to once per bar was checked.
3. Intrabarordergeneration is true.

However it seemed the code did not recognize the buy if low[1]>MA because even it is false buy signal was generated. I noticed that this happened preceding a stop sell execution the previous bar.

Please help!

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Exit Strategy
NinjaTrader
Increase in trading performance by 75%
The Elite Circle
PowerLanguage & EasyLanguage. How to get the platfor …
EasyLanguage Programming
REcommedations for programming help
Sierra Chart
How to apply profiles
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
31 thanks
Spoo-nalysis ES e-mini futures S&P 500
28 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
20 thanks
GFIs1 1 DAX trade per day journal
17 thanks
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,433 since Apr 2013
Thanks Given: 481
Thanks Received: 1,627

risaldeb,

it's hard to tell what is going on without knowing your code. It's possible that you are using a flag for the entry condition check that is not reset and simply stays true, but there are many other reasons. One could only guess without seeing the code.

Regards,
ABCTG

Follow me on Twitter Reply With Quote
  #3 (permalink)
 
Jura's Avatar
 Jura   is a Vendor
 
Posts: 775 since Apr 2010
Thanks Given: 2,352
Thanks Received: 690


I think it might also help if you share what you're trying to do. From the three points that your code does, I get that it should buy when the previous low is above a moving average value. But in point 2 you mention 'orders from all signal'. Does that mean you're combining several signals into one?

So as ABCTG says, post the code (or a reduced example that replicates the problem). But I'd add to that to also clarify your goal(s). Perhaps your code is needlessly complicating things.

Reply With Quote
  #4 (permalink)
risaldeb
Hong Kong
 
Posts: 10 since Feb 2015
Thanks Given: 1
Thanks Received: 0


Jura View Post
I think it might also help if you share what you're trying to do. From the three points that your code does, I get that it should buy when the previous low is above a moving average value. But in point 2 you mention 'orders from all signal'. Does that mean you're combining several signals into one?

So as ABCTG says, post the code (or a reduced example that replicates the problem). But I'd add to that to also clarify your goal(s). Perhaps your code is needlessly complicating things.

ABCTG, Jura, Many thanks. Here's the code which is mostly conditional.

NoTrade= Low[1]<var0 or Low<var0;

BuyCondition= (TimeCondition=True)
And (MarketPosition=0)
And (TradeCondition1=True)
//And (TradeCondition2=True)
And oParCl< Low
And (NoTrade=False);

If BuyCondition Then //Begin
Buy ( "Buy-SAR" ) Next Bar at Market;



setstoploss (SellStop);//Why after stop execution a buy order executed on next bar even no buy signal???

SetPercentTrailing( ProfitTrigger$, PctTrailing ) ;
SetProfitTarget( ProfitTarget$ );

Reply With Quote
  #5 (permalink)
 
Jura's Avatar
 Jura   is a Vendor
 
Posts: 775 since Apr 2010
Thanks Given: 2,352
Thanks Received: 690

Your code misses the variables and IOG declaration, which is not a big thing but it makes me wonder whether it's complete.

Why did you choose to use intra-bar order generation, by the way? If you may know, SetStopLoss is also evaluated intra-bar and thus does not need IOG, while IOG can also affect your variables' values (see IntraBarPersist).

Now there's nothing wrong with using IOG, but if you have an issue with your code I'd suggest to bring the code back to its basic form and then step-by-step add each new component to see what breaks it.

Reply With Quote
  #6 (permalink)
risaldeb
Hong Kong
 
Posts: 10 since Feb 2015
Thanks Given: 1
Thanks Received: 0

Hi Jura,

I use IOG so it can react to intra day opportunity. Here's what I did. I remove one by one all the buy signals and the result was still the same. That is it still Buy at open after the previous bar was stopped or executed a sell signal. Even I checked the "limit entries from same signal in this strategy to once per bar" it still trade the next bar. I am lost now!

I suspect that a spill over of signal from the previous bar that is executed at the next bar open. How can I ensure that the code will only buy if the condition is true. Right now even if false it still buy then immediately sell it soon after.

Reply With Quote
  #7 (permalink)
 
Jura's Avatar
 Jura   is a Vendor
 
Posts: 775 since Apr 2010
Thanks Given: 2,352
Thanks Received: 690


risaldeb View Post
Here's what I did. I remove one by one all the buy signals and the result was still the same. That is it still Buy at open after the previous bar was stopped or executed a sell signal. Even I checked the "limit entries from same signal in this strategy to once per bar" it still trade the next bar. I am lost now!

I suspect that a spill over of signal from the previous bar that is executed at the next bar open. How can I ensure that the code will only buy if the condition is true. Right now even if false it still buy then immediately sell it soon after.

If I look at the code you previously posted (with the `BuyCondition` variable), then that should buy only if the condition is true. So based on that code snippet I don't see a reason why this behaviour occurs.

Have you tried outputting the variable that you use for submitting buy orders (e.g., `BuyCondition`) on every script calculation to verify that it doesn't remain true?

It might also help to double-check that the variable used for submitting the order (e.g., `BuyCondition`) is only assigned a value above the code that submits the order. If you place `BuyCondition` below the code that submits the order, then this variable will be true on the next script calculation even though it shouldn't be.

Otherwise, can you perhaps post the full script that is causing this problem? Perhaps with more eyes looking at the code we can spot the error faster.

Reply With Quote
  #8 (permalink)
risaldeb
Hong Kong
 
Posts: 10 since Feb 2015
Thanks Given: 1
Thanks Received: 0

After isolating buy signal one by one. I think I found the culprit. Since the IOG is True, the buy signal Low[1]>var0 is executed per tick and the code is doing what it meant as coded but not what I intended to do.

I set the chart to 30 minutes and I like the last bar Low should be > var0 to buy. But unfortunately I am not getting it if the last tick low from the previous bar is higher than var0 even if the Low of the previous 30 minute bar is < var0.

How can I code that the last 30 min bar Low is > var0 to buy and IOG = True?

Reply With Quote
  #9 (permalink)
 
Jura's Avatar
 Jura   is a Vendor
 
Posts: 775 since Apr 2010
Thanks Given: 2,352
Thanks Received: 690


risaldeb View Post
I set the chart to 30 minutes and I like the last bar Low should be > var0 to buy. But unfortunately I am not getting it if the last tick low from the previous bar is higher than var0 even if the Low of the previous 30 minute bar is < var0.

How can I code that the last 30 min bar Low is > var0 to buy and IOG = True?

You can use BarStatus to ensure that `var0` is calculated on bar close and not on every tick. For example:

 
Code
Variables:
  var0(0),
  buyOrder(false);

if (BarStatus(1) = 2) then begin

  // Calculate var0 on bar close
  var0 = ...
  
  // Generate the order condition
  if (Low > var0) then
    buyOrder = true;

end;

// This code is executed on every tick
if (buyOrder = true) then begin

  // Submit order

end;

Reply With Quote
Thanked by:
  #10 (permalink)
risaldeb
Hong Kong
 
Posts: 10 since Feb 2015
Thanks Given: 1
Thanks Received: 0


Hi Jurra,

Many thanks. Your code above works. I only changed (BarStatus(1) = 1) then it worked according to my strategy otherwise if it is (BarStatus(1) = 2) it takes the close of the last bar.

Best,
R

Reply With Quote




Last Updated on May 27, 2015


© 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