NexusFi: Find Your Edge


Home Menu

 





TS with grid orders in EasyLanguage


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one Dan46 with 2 posts (0 thanks)
    2. looks_two mwtzzz with 2 posts (0 thanks)
    3. looks_3 bomberone1 with 1 posts (0 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 3,239 views
    2. thumb_up 0 thanks given
    3. group 4 followers
    1. forum 6 posts
    2. attach_file 0 attachments




 
Search this Thread

TS with grid orders in EasyLanguage

  #1 (permalink)
Dan46
Milan Italy
 
Posts: 2 since Feb 2013
Thanks Given: 0
Thanks Received: 0

Hi guys, I’m quite new to programming and need some help for a system I’m trying to code.

I want the TS to buy at MovingAverage – X points (first trade).
Then buy every time the price drops Y points following a “grid style”.

Example:
X = 40
Y = 30
Moving average @ 240
First buy limit @ 200
Second buy limit @ 170
Third buy limit @ 140
4th buy limit @ 110
5th buy limit @ 80
6th….

And close all open positions once the price touch the MovingAverage.


This is the code I tried to write:

 
Code
inputs: Len(100), X(40), Y(30);
vars: entrylevel(0), previouslevel(0), nextlevel(0);

//first entry
If marketposition = 0 then begin
entrylevel = Average(Close, Len)- X;
buy next bar at entrylevel limit;
end;

//next entries
If marketposition > 0 and currentshares > 0 then begin
   If currentshares>currentshares[1] then previouslevel=minlist(open, nextlevel,entrylevel);
   nextlevel=previouslevel-Y;
end;

if mp>0 then buy next bar at nextlevel limit;

//exit
if marketposition > 0 then sell next bar at Average(Close, Len ) limit;
The problems I find are:
1) The levels aren’t always respected (honestly I can’t understand why sometime the levels are correct and sometime not)
2) In this way (next bar limit) the orders are executed no more than once per bar, even if a single bar drop more than Y points (that would mean more than a single trade per bar)

Can you guys please help me with this code?
Thank you in advance

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Cheap historycal L1 data for stocks
Stocks and ETFs
Better Renko Gaps
The Elite Circle
How to apply profiles
Traders Hideout
REcommedations for programming help
Sierra Chart
 
  #3 (permalink)
mwtzzz
Sunnyvale, CA
 
Posts: 171 since Dec 2012
Thanks Given: 8
Thanks Received: 107


The limit order tells it to buy at that price or better, so are you sure the discrepensy isn't just a reflection of getting it at a better price?

Reply With Quote
  #4 (permalink)
Dan46
Milan Italy
 
Posts: 2 since Feb 2013
Thanks Given: 0
Thanks Received: 0


mwtzzz View Post
The limit order tells it to buy at that price or better, so are you sure the discrepensy isn't just a reflection of getting it at a better price?

hi mwtzzz, I think I can exclude that the different levels the TS buys are due to better price fills because it happens for example that the TS buys few candles after the candle that closed under the theoretical price to buy..

example: the TS bought at 130, next theoretical price to buy is 100
it happens that there are candles that close at let's say 95 and the TS still don't buys the next contract...

(sorry for my bad english)

Reply With Quote
  #5 (permalink)
mwtzzz
Sunnyvale, CA
 
Posts: 171 since Dec 2012
Thanks Given: 8
Thanks Received: 107


Dan46 View Post
hi mwtzzz, I think I can exclude that the different levels the TS buys are due to better price fills because it happens for example that the TS buys few candles after the candle that closed under the theoretical price to buy..

example: the TS bought at 130, next theoretical price to buy is 100
it happens that there are candles that close at let's say 95 and the TS still don't buys the next contract...

(sorry for my bad english)

If you're trying to add to existing position, be sure to enable "pyramiding orders" in Format Strategies > Properties for All.

also use some "Print()" statements for debugging. You can Print the entrylevel and currentshares to make sure it's doing what it should be

Reply With Quote
  #6 (permalink)
 bomberone1 
London
 
Experience: Beginner
Platform: MultiCharts
Posts: 277 since Nov 2010
Thanks Given: 14
Thanks Received: 29

Do you find a solution?

Reply With Quote
  #7 (permalink)
OMEGAA
milan italy
 
Posts: 10 since Nov 2022
Thanks Given: 0
Thanks Received: 0

Do you want to enter every time the price drops by X points and close all positions once it touches the moving average line?

Reply With Quote




Last Updated on July 6, 2023


© 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