Why Alerts do not appear when trading my Paper account?
Author: asagar00
Creation Date: 5/27/2020 3:00 PM
profile picture

asagar00

#1
Hi,

I am not able to get my programs to trade in automated tradiing in the paper account. To check it's not my program, I developed a simple program that buys & sells every 3rd bar -- even that does not place alerts (orders). Attached are photos showing the settings.

Any feedback on what I could be doing wrong?

Test Program (to buy / sell every 3rd bar):

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

Eugene

#2
Hi,

You should never use a bar value greater than 1. Provided you've loaded more than 200 bars (or adjusted the code to start from bar 1 since it isn't actually using the moving averages), fixing the exit code for "bar+1" should do the trick.

P.S. These photos are a start (so to say - very politely) but for your future reference, here's how to take a screenshot:

1. Strike Prt Scrn key on your keyboard
2. Start MS Paint (built in any Windows)
3. Ctrl-V or Edit > Paste
4. Save as PNG (not JPG)

That's what it takes.
profile picture

Cone

#3
Slightly easier method for image capture in Win 10 since you don't have to open Paint:

1. Strike Windows Key + Shift + S (easy to remember S => Screen)
2. Drag around the area to capture (image auto saved to clipboard)
3. Click on the resulting image dialog to open "Snip & Sketch"
4. Click the floppy disk icon (upper right side) to save to disk.
profile picture

asagar00

#4
Hi Eugene,

Sorry about the photos, will send PNG format in future.

Thanks for the feedback, I fixed this in my code & now it's placing trades.

I appreciate your help. Thanks!
profile picture

asagar00

#5
Cone,

Thanks. I should have done what you suggested; it is a lot easier than taking photos on the phone & e-mailing it to my account (and lot better quality)! I went about that 'bass-ackwards'.
profile picture

Eugene

#6
Glad to help you!
profile picture

asagar00

#7
One more question -- ActivePostitions.Count is always zero, and the strategy always buys. Even with trivial code like below (alternating buying & selling), I can't get the program to sell:
CODE:
Please log in to see this code.

===
I have even used the Possizer options to configure max open to 1 (see attached)... but the program still buys, never sells. I appreciate your feedback on what I could be doing wrong. Thanks,
profile picture

Cone

#8
You're setting the variable bar to the last bar of the chart, therefore this is no hypothetical trading history, i.e., Wealth-Lab does not have a position to work with.

If you have a live position to sell with WLP, then you need Wealth-Lab to create a hypothetical Position to represent that live Position. If you just want to run the sell logic, do it like this:

CODE:
Please log in to see this code.


This is a bad example to use for intraday trading!
This script will ALWAYS have an Active Position and will check to exit it (if the Close crosses over the 20 bar SMA). If you want to accomplish something specific, let me know what it is.
profile picture

asagar00

#9
Hi Cone,

Say for example I want to buy when SMA(50) crosses over SMA(200). I want to do the opposite when SMA(50) crosses under SMA(200); but the code does not do this. I would like only one open position (in each symbol).

In all the simulation runs, my code does buy & sell exactly according to my intent.

When I convert the simulation to automated (paper) trading by removing the 'for' loop and substituting: bar = Bars.Count-1;
* Every 5-minutes, it buys the a new position -- but never sells that open position
* When I check PrintDebug(ActivePositions.Count) -- it is always zero (which is why it never sells)

The code you had given above would create a hypothetical buy position & sell that position later. But I want to sell the most recent open position (should be only 1 open position). Would the code you gave above do this?

Any feedback on how I could sell the open position I created 5-minutes ago (i.e. if sell conditions met)? Thanks,
profile picture

asagar00

#10
Hi Cone,

As an addendum, I want only one open position in any given (stock) symbol. I thought I had ensured that in the 'Position Options' (MS123) by setting Max Open & Max Long to 1. But every 5-minutes the code purchases additional shares. Any thoughts on how I can prevent this?

Thanks,
profile picture

asagar00

#11
Hi Cone,

I figured this out. I had a: SellAtMarket(bar + 2, p, "Sell Third Bar");

I should not have used a bar+2; I went through all the documentation again & a bar+2 is against the rules. Once I corrected this, the program started buying & selling. Thanks,
profile picture

Eugene

#12
Good news!
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).