Supply entry prices from File to make trades?
Author: mrsic
Creation Date: 4/29/2019 9:50 AM
profile picture

mrsic

#1
Hallo,
I am not a programmer but i do my best.
Can anyone help me with this staff. I just want test only a single Symbol. I know, i can create a DataSet with one single Symbol. But i want test different Symbols with different Price Action.


CODE:
Please log in to see this code.


Thanks.
profile picture

Eugene

#2
Hi,

What do you mean by testing different symbols with different price action? What do different symbols have to do with testing on single symbol then?

Please clarify your task in plain English and we'll find a solution.
profile picture

mrsic

#3
Hi,

What I mean is this:
I want to buy for example 10 different stocks (AAPL, XOM and so on). And I want to buy each one at a certain price. The prices are different. For example XOM at $ 50, AAPL $ 100 and so on. I hope it is more understandable now - i am working on it.
profile picture

Eugene

#4
You naturally buy each symbol at a different price, don't you? But what is the logic behind buying XOM at $50 etc in your example? Let's lay down your cards. I'd like to understand your objective rather than to just show a sample code.
profile picture

mrsic

#5
The logic is simple as it is.
I look at the chart for the last 5-15 years and after that, i will set a Price lower Limit. This means, if the Price fall under the Limit i will buy the stock. And i will sold the stock at a certain Price. I will set this individuell. I don't want read every day the chart of a certain stock, i would like to automate this. Every day i want looking for interesting stocks, and if i finded one, i want extend the code with this new stock and set a Price lower Limit + Price highest Limit. This is more a fundamental Strategy.
profile picture

Eugene

#6
It's getting clearer. At some point it occurred to me that you might be thinking about backtesting historical trades.

So you're saying, "if the Price fall under the Limit i will buy the stock. And i will sold the stock at a certain Price." Assuming you enter and exit at certain prices, create a text file called AAPL.csv (same for XOM with its own prices etc.) at C:\temp with this contents:
CODE:
Please log in to see this code.


Below is a quick and dirty parser (no error handling, no bells & whistles):
CODE:
Please log in to see this code.
profile picture

mrsic

#7
Thanks Eugene.

I do not know what I'm doing wrong with the exit conditions. For Example, Close APPL 30.04.2019: 200.67
this my values to test the exit conditions:
CODE:
Please log in to see this code.


And the result is: See Attachment.

I think i should get a sell Alert!

Can anyone help me.


CODE:
Please log in to see this code.

profile picture

Eugene

#8
QUOTE:
I think i should get a sell Alert!

No you shouldn't. You've restricted the script to operate on the last bar and so there can only be an entry alert.

Also make sure you've read this FAQ when considering this type of same bar trading: I want to test a strategy that buys and sells with stop/limit orders on the same bar.
profile picture

mrsic

#9
Hi Eugene,

cvs. is pretty cool stuff.

It seems that I need a time Priority! And there is no other way?

I have tried using AtMarket - it seems the same "operate on the last bar".
profile picture

Eugene

#10
Hi Damir,

The script is made to work on the last bar only. For this reason it cannot be used to exit a position using any order as it cannot keep track of it. Its "memory" spans just the last bar, "forgetting" about the rest.

For auto-trading you might be interested in RiskStopLevel and AutoProfitLevel. This requires auto-trading enabled (either Paper Trading or a 3rd party broker provider). More detail in the Help menu > Preferences > Trading > Allow Same Bar Exits for Auto-Trading. Check out Cone's detailed explanation in this thread:

Same Bar Exit, post #6
profile picture

mrsic

#11
Thanks Eugene,

i will check this but honestly it is enough for me mechanically.
profile picture

Eugene

#12
Anyway, a time-based Priority wouldn't help your task since it's not about backtesting.
profile picture

mrsic

#13
i am seeing the forest for the trees - and what would help?
profile picture

Eugene

#14
For starters, try to read and understand Cone's explanation. I can't say any better.
profile picture

mrsic

#15
Thanks.
profile picture

Eugene

#16
You're welcome.
profile picture

mrsic

#17
Hi,
i am not a programmer but i do my best. Can someone give me a hint - something is mixed up.

I am getting 4 alerts although the Entry and the Exit Price is above the Close Price. See Attachments.

I am getting 4 alerts. Two Buys, two Shorts. Although the Entry Price is above the close price and the Exit Price above the Close Price. See Attachments.

QUOTE:
AAPL 205;230, ABT 80;110


CODE:
Please log in to see this code.
profile picture

Eugene

#18
Look, it's not possible to tell whichever of your two limit Alerts gets executed on the next bar. And since the Position is still null the control falls to the short entry order. Therefore both are staged. This is not backtesting.
profile picture

mrsic

#19
I tried to follow the instructions from Cone Post#6 Same Bar Exit.
It seems that my RiskStopLevel are useless. Maybe someone is here who can help me and solve the task? Until then i try it further.

greetings
damir
profile picture

Eugene

#20
Don't complicate it for now with your same bar long/short entries.

Take version from post #7, pay more attention to my reply in post #8 and #10 (this is crucial and still not fixed in your code), add RiskStopLevel and/or an AutoProfitLevel. At the risk of repeating, there is no "memory" of signals as you've eliminated it yourself:

QUOTE:
The script is made to work on the last bar only. For this reason it cannot be used to exit a position using any order as it cannot keep track of it. Its "memory" spans just the last bar, "forgetting" about the rest.


I repeated it twice and your code in #17 still persists in the error:

CODE:
Please log in to see this code.
profile picture

mrsic

#21
Ih Eugene, i cannot use for-loop on the last bar! Because the script is made on the last bar.

The box is activated.
QUOTE:
Help menu > Preferences > Trading > Allow Same Bar Exits for Auto-Trading.


I have read the post x-times but I will not be smarter.
This one also works not correctly.

CODE:
Please log in to see this code.

profile picture

Eugene

#22
QUOTE:
Because the script is made on the last bar.

Sadly we're going in circles. :(

If the strategy's purpose is to trade on the last bar only i.e. "from Bars.Count-1 to Bars.Count-1" then it cannot establish a Position. Or in other words you've made a screener out of it. You can develop better understanding of the concept if you read the WealthScript Programming Guide:

Techniques > Creating a Screener
Programming Trading Strategies > Trading Loop

One bar is not enough to create an entry alert (at bar), record the trade for bar+1, and then issue an exit signal (on what essentially is "bar+2").

QUOTE:
This one also works not correctly.

Because the code above does not make sense. If you take a minute of your time to review the QuickRef for RiskStopLevel and AutoProfitLevel, you'd notice that you're overlooking some key points:

Prior to issuing the BuyAt*, you should set RiskStopLevel ... as the initial stop level for the long Position.
...
Once a RiskStopLevel is established for a Position, do not change it. ...Reassigning its value after the Position is established is effectively a peeking error.


It's all documented and exemplified. Hope this is clear as I've got nothing else to comment on this.
profile picture

mrsic

#23
Thanks Eugene.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).