- ago
Why does this code generate only:

--SPY--
index: 5010, profit: -6,9300000000008595
index: 5011, profit: -6,9300000000008595
index: 5012, profit: -6,9300000000008595
index: 5013, profit: -6,9300000000008595
index: 5014, profit: -6,9300000000008595
index: 5015, profit: -6,9300000000008595
index: 5016, profit: -6,9300000000008595
index: 5017, profit: -6,9300000000008595
index: 5018, profit: -6,9300000000008595
index: 5019, profit: -6,9300000000008595
index: 5020, profit: -6,9300000000008595
index: 5021, profit: -6,9300000000008595
index: 5022, profit: -6,9300000000008595
index: 5023, profit: -6,9300000000008595
index: 5024, profit: -6,9300000000008595
index: 5025, profit: -6,9300000000008595
index: 5026, profit: -6,9300000000008595
index: 5027, profit: -6,9300000000008595
index: 5028, profit: -6,9300000000008595


CODE:
namespace WealthScript1 { public class MyStrategy : UserStrategyBase {       public override void Initialize(BarHistory bars) {    } public override void Execute(BarHistory bars, int idx)       {          if (idx < 125)             return;          {             if (bars.Close[idx] > bars.High[idx - 1])                PlaceTrade(bars, TransactionType.Buy, OrderType.Market); }          foreach (Position long_pos in OpenPositions)          if (long_pos != null &             long_pos.PositionType == PositionType.Long)             {                if (long_pos.Profit < 0)                   WriteToDebugLog(String.Format("index: {0}, profit: {1}", idx, long_pos.Profit));             }          foreach (Position long_pos in OpenPositions)             if (long_pos != null & long_pos.PositionType == PositionType.Long)             {                if (long_pos.EntryBar < idx - 25)                {                   ClosePosition(long_pos, OrderType.Market);                }             }     } } }
0
633
5 Replies

Reply

Bookmark

Sort
- ago
#1
Because Position.Profit or .ProfitPct is the final value. Are you looking for ProfitAsOf / ProfitPctAsOf?
0
- ago
#2
Eugene, oh, I see, thanx. But what is the "final value"? Is it a strategy-ticker total expanding profit, but accessed by the Positions's property?
0
- ago
#3
The Profit property returns the total profit of the Position (minus commissions) on the exit bar.
0
Glitch8
 ( 8.38% )
- ago
#4
That property is mainly meant to be consumed by Performance Visualizers.
0
- ago
#5
I got it, thanx.
0

Reply

Bookmark

Sort