Click here to Skip to main content
15,904,415 members
Home / Discussions / C#
   

C#

 
AnswerRe: The performance of LINQ vs. traditional iteration Pin
Pete O'Hanlon30-Apr-13 6:38
mvePete O'Hanlon30-Apr-13 6:38 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
Rob Philpott30-Apr-13 6:49
Rob Philpott30-Apr-13 6:49 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
Simon_Whale30-Apr-13 23:41
Simon_Whale30-Apr-13 23:41 
AnswerRe: The performance of LINQ vs. traditional iteration Pin
Richard Deeming30-Apr-13 7:24
mveRichard Deeming30-Apr-13 7:24 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
Rob Philpott30-Apr-13 7:54
Rob Philpott30-Apr-13 7:54 
AnswerRe: The performance of LINQ vs. traditional iteration Pin
jschell30-Apr-13 9:54
jschell30-Apr-13 9:54 
QuestionCrystal Report without preview print is not working in published file Pin
swathipd30-Apr-13 0:34
swathipd30-Apr-13 0:34 
AnswerRe: Crystal Report without preview print is not working in published file Pin
Eddy Vluggen30-Apr-13 1:00
professionalEddy Vluggen30-Apr-13 1:00 
GeneralRe: Crystal Report without preview print is not working in published file Pin
swathipd1-May-13 19:00
swathipd1-May-13 19:00 
GeneralRe: Crystal Report without preview print is not working in published file Pin
Eddy Vluggen2-May-13 11:00
professionalEddy Vluggen2-May-13 11:00 
QuestionC# IE toolbar button runs bat or PS script. works one time then doesn't anymore. Pin
Member 990412330-Apr-13 0:19
Member 990412330-Apr-13 0:19 
Questionmodal popup inside another modal popup Pin
Gangula Sneha30-Apr-13 0:05
Gangula Sneha30-Apr-13 0:05 
AnswerRe: modal popup inside another modal popup Pin
GuyThiebaut30-Apr-13 0:38
professionalGuyThiebaut30-Apr-13 0:38 
QuestionRe: modal popup inside another modal popup Pin
Eddy Vluggen30-Apr-13 0:59
professionalEddy Vluggen30-Apr-13 0:59 
AnswerRe: modal popup inside another modal popup Pin
GuyThiebaut30-Apr-13 1:45
professionalGuyThiebaut30-Apr-13 1:45 
GeneralRe: modal popup inside another modal popup Pin
Eddy Vluggen30-Apr-13 2:11
professionalEddy Vluggen30-Apr-13 2:11 
GeneralRe: modal popup inside another modal popup Pin
GuyThiebaut30-Apr-13 2:22
professionalGuyThiebaut30-Apr-13 2:22 
GeneralRe: modal popup inside another modal popup Pin
Eddy Vluggen30-Apr-13 2:52
professionalEddy Vluggen30-Apr-13 2:52 
GeneralRe: modal popup inside another modal popup Pin
GuyThiebaut30-Apr-13 2:53
professionalGuyThiebaut30-Apr-13 2:53 
QuestionVFW blank frames at start of avi Pin
Boris The Bold29-Apr-13 23:24
Boris The Bold29-Apr-13 23:24 
QuestionBuying stock is easy, selling it is worse... loop problems? Pin
lordoftrades29-Apr-13 22:33
lordoftrades29-Apr-13 22:33 
Hello

I'm trying to create a program that scan the values and compare values against some average highest or loweste values. It seems to me that the entry is no problem, but getting out of the position is not working as it should.

I'm used to VBA, and there I'd just set up a loop to start IF an entrysignal was trigged. And that loop would run until exitsignal was trigged...

But I'm not experienced at all with writing in C#, so I'm not sure how this code actually runs, ie step-by-step:

C#
// Check whether the indicator value is oversold.
            if (Value < yesterdayslowest50Value && yyesterdayslowest50Value > yesterdaysValue) {
                // Check whether a short position exists for the symbol.
                if (_enableShorting && PositionExists(IQ_TradeStatus.OPEN, symbolIndex, IQ_Direction.SHORT_SIDE)) {
                    // Generate a buy to cover market order.
                    BrokerMarket(IQ_ActionType.BUY_TO_COVER, symbolIndex, 0, IQ_TIF.DAY, "CoverToLong");
                }
                // Check whether there are no long positions for the symbol.
                if (!PositionExists(IQ_TradeStatus.OPEN, symbolIndex, IQ_Direction.LONG_SIDE)) {
                    // Generate a buy market order.
                    int orderIndex = BrokerMarket(IQ_ActionType.BUY, symbolIndex, 0, IQ_TIF.DAY, "Long");
                    // Set a stop loss on the order.
                    BrokerSetStopLossPercent(orderIndex, _stopLoss, true, "");
                    // Set a take profit on the order.
                    BrokerSetTakeProfitPercent(orderIndex, _takeProfit, true, "");
                    // Set a trailing stop loss on the order.
                    BrokerSetTrailingStopLoss(orderIndex, _isPercent, _trailingStop, "");
                }
                //When to exit:
                if(Value > yesterdayshighest13Value && yesterdaysValue < yyesterdayshighest13Value && PositionExists(IQ_TradeStatus.OPEN, symbolIndex))
                    {
                        int[] positionIndexes = PositionIndexList(IQ_TradeStatus.OPEN, symbolIndex);
                        double quantity = PositionQuantity(positionIndexes[0]);
                        BrokerMarket(IQ_ActionType.SELL, symbolIndex, quantity, IQ_TIF.DAY, "Sell");
                    }
            }
            // Check whether the indicator value is overbought.
            else if (Value > yesterdayslowest13Value && yyesterdayslowest13Value < yesterdaysValue) {
                // Check whether a long position exists.
                if (PositionExists(IQ_TradeStatus.OPEN, symbolIndex, IQ_Direction.LONG_SIDE)) {
                    // Generate a sell market order.
                    BrokerMarket(IQ_ActionType.SELL, symbolIndex, 0, IQ_TIF.DAY, "SellToShort");
                }
                // Check whether a short position doesn't exist.
                if (_enableShorting && !PositionExists(IQ_TradeStatus.OPEN, symbolIndex, IQ_Direction.SHORT_SIDE)) {
                    // Generate a sell short market order.
                    int orderIndex = BrokerMarket(IQ_ActionType.SELL_SHORT, symbolIndex, 0, IQ_TIF.DAY, "Short");
                    // Set a stop loss on the order.
                    BrokerSetStopLossPercent(orderIndex, _stopLoss, true, "");
                    // Set a take profit on the order.
                    BrokerSetTakeProfitPercent(orderIndex, _takeProfit, true, "");
                    // Set a trailing stop loss on the order.
                    BrokerSetTrailingStopLoss(orderIndex, _isPercent, _trailingStop, "");
                }
                //When to exit:
                if(Value < yesterdayslowest13Value && yesterdaysValue > yyesterdayslowest13Value && PositionExists(IQ_TradeStatus.OPEN, symbolIndex))
                    {
                        int[] positionIndexes = PositionIndexList(IQ_TradeStatus.OPEN, symbolIndex);
                        double quantity = PositionQuantity(positionIndexes[0]);
                        BrokerMarket(IQ_ActionType.BUY_TO_COVER, symbolIndex, quantity, IQ_TIF.DAY, "Cover");
                    }
            }


It seems that my code have issues exiting the trades. BTW I've used IQBrokers software to program this.

If anyone see some obviouse mistake I'd appreciate it.
Kind regards
Espen

AnswerRe: Buying stock is easy, selling it is worse... loop problems? Pin
Eddy Vluggen29-Apr-13 23:04
professionalEddy Vluggen29-Apr-13 23:04 
GeneralRe: Buying stock is easy, selling it is worse... loop problems? Pin
lordoftrades29-Apr-13 23:07
lordoftrades29-Apr-13 23:07 
GeneralRe: Buying stock is easy, selling it is worse... loop problems? Pin
Richard MacCutchan29-Apr-13 23:23
mveRichard MacCutchan29-Apr-13 23:23 
GeneralRe: Buying stock is easy, selling it is worse... loop problems? Pin
Eddy Vluggen29-Apr-13 23:32
professionalEddy Vluggen29-Apr-13 23:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.